diff --git a/task_management_app/src/app/api/users/route.ts b/task_management_app/src/app/api/users/route.ts index de74f50..2cae26a 100644 --- a/task_management_app/src/app/api/users/route.ts +++ b/task_management_app/src/app/api/users/route.ts @@ -8,14 +8,25 @@ export async function GET(req: NextRequest){ if(!connectionString){ return new Response('No db connection string', {status:500}); } - if(!url.searchParams.has('ids')){ - return Response.json([]) - } - const emails = url.searchParams.getAll('ids'); await mongoose.connect(connectionString) - const users = await User.find({email: emails}); + let users = []; + + if(url.searchParams.get('ids')){ + const emails = url.searchParams.get('ids')?.split(','); + users = await User.find({email:{$in:emails}}); + } + if(url.toString().includes('?search=')){ + const searchPhrase = url.searchParams.get('search'); + const searchRegex = `.*${searchPhrase}.*`; + users = await User.find({ + $or: [ + {name: {$regex: searchRegex}}, + {email: {$regex: searchRegex}}, + ], + }) + } return Response.json(users.map((u:UserType) => ({ id:u.email, name:u.name, diff --git a/task_management_app/src/app/globals.css b/task_management_app/src/app/globals.css index f61d858..849a8e3 100644 --- a/task_management_app/src/app/globals.css +++ b/task_management_app/src/app/globals.css @@ -4,7 +4,7 @@ button[type="button"], button[type="submit"], button.primary{ - @apply bg-[#164863] text-white p-2 text-sm font-semibold rounded-md flex + @apply bg-[#164863] text-white p-2 text-sm font-semibold rounded-md flex w-full justify-center items-center text-center } button[type="submit"], button.primary{ @apply bg-[#427D9D] rounded-md diff --git a/task_management_app/src/app/liveblocks.config.ts b/task_management_app/src/app/liveblocks.config.ts index 9eaa446..7280970 100644 --- a/task_management_app/src/app/liveblocks.config.ts +++ b/task_management_app/src/app/liveblocks.config.ts @@ -2,13 +2,17 @@ import { LiveList, LiveObject, ThreadData, createClient } from "@liveblocks/clie import { createRoomContext } from "@liveblocks/react"; const client = createClient({ - authEndpoint: "/api/liveblocks-auth", - throttle: 100, - resolveUsers: async ({userIds}) => { - const params = new URLSearchParams(userIds.map(id => ['ids', id])); - const response = await fetch(`/api/users?` + params.toString()); - return await response.json(); - }, + authEndpoint: "/api/liveblocks-auth", + throttle: 100, + resolveUsers: async ({userIds}) => { + const response = await fetch(`/api/users?ids=` + userIds.join(',')); + return await response.json(); + }, + resolveMentionSuggestions: async ({text}) => { + const response = await fetch(`/api/users?search=` + text); + const users = await response.json(); + return users.map((user:UserMeta) => user.id); + } }); diff --git a/task_management_app/src/components/Card.tsx b/task_management_app/src/components/Card.tsx index 6c13744..1529820 100644 --- a/task_management_app/src/components/Card.tsx +++ b/task_management_app/src/components/Card.tsx @@ -25,7 +25,7 @@ const Card = ({id, name}: {id:string, name:string}) => { return ( - + {name} ) diff --git a/task_management_app/src/components/Column.tsx b/task_management_app/src/components/Column.tsx index 941133a..1ebaed2 100644 --- a/task_management_app/src/components/Column.tsx +++ b/task_management_app/src/components/Column.tsx @@ -65,7 +65,7 @@ const Column = ({id, name}: ColumnProps) => { return ( -
Hello,
{session?.user?.name} +{card?.name}
diff --git a/task_management_app/src/lib/authOptions.ts b/task_management_app/src/lib/authOptions.ts index aa12abc..1f49087 100644 --- a/task_management_app/src/lib/authOptions.ts +++ b/task_management_app/src/lib/authOptions.ts @@ -4,11 +4,12 @@ import GoogleProvider from "next-auth/providers/google"; import { AuthOptions } from "next-auth"; export const authOptions: AuthOptions = { - providers: [ - GoogleProvider({ - clientId: process.env.GOOGLE_CLIENT_ID as string, - clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, - }) - ], - adapter: MongoDBAdapter(clientPromise), + secret: process.env.AUTH_SECRET, + providers: [ + GoogleProvider({ + clientId: process.env.GOOGLE_CLIENT_ID as string, + clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, + }) + ], + adapter: MongoDBAdapter(clientPromise), } \ No newline at end of file