Starfire world peace#30
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds a Clerk-to-backend user-sync flow: a new /api/v1/auth/sync route on the core service finds-or-creates a User row keyed by clerkId, and a new client-side useAuthSync hook calls it on login and caches the returned UUID in localStorage for use as userId in chat requests. Also restores the previously commented-out validate(chatSchema) middleware on the chat route and removes an unused Tooltip import.
Changes:
- New backend auth module (route/controller/service/repository) implementing a
findOrCreateuser-sync endpoint. - New
useAuthSyncReact hook wired into the dashboard layout via anAuthProviderwrapper;ChatWindownow readsuserIdfromlocalStorageinstead of a hard-coded UUID. - Re-enabled
validate(chatSchema)on the chat POST route.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/core/src/app.ts | Mounts the new authRouter under /api/v1/auth. |
| apps/core/src/modules/auth/auth.route.ts | New router exposing POST /sync. |
| apps/core/src/modules/auth/auth.controller.ts | Calls authSync and returns { success, userId }. |
| apps/core/src/modules/auth/auth.service.ts | Find-or-create user by clerkId via Prisma. |
| apps/core/src/modules/auth/auth.repository.ts | Duplicate of the service file with identical logic. |
| apps/core/src/modules/auth/auth.schema.ts | Empty placeholder for a validation schema. |
| apps/core/src/modules/chat/chat.route.ts | Re-enables validate(chatSchema) on the chat route. |
| apps/web/app/hooks/use-auth-sync.ts | Client hook posting Clerk profile to the sync endpoint and caching userId. |
| apps/web/app/dashboard/layout.tsx | Imports the hook and mounts a null-returning AuthProvider. |
| apps/web/app/components/chat/ChatWindow.tsx | Sources userId from localStorage instead of a hard-coded UUID. |
| apps/web/app/components/chat/ChatInput.tsx | Removes an unused Tooltip import. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1
to
+35
| import { prisma } from "../../lib/prisma.js"; | ||
|
|
||
| // 🔄 Find or create user | ||
| export async function authSync(data: { | ||
| clerkId: string; | ||
|
|
||
| name: string; | ||
|
|
||
| email?: string; | ||
| }) { | ||
| // 1️⃣ Find existing user | ||
| const existingUser = await prisma.user.findUnique({ | ||
| where: { | ||
| clerkId: data.clerkId, | ||
| }, | ||
| }); | ||
|
|
||
| // 2️⃣ Return if exists | ||
| if (existingUser) { | ||
| return existingUser; | ||
| } | ||
|
|
||
| // 3️⃣ Create new user | ||
| return prisma.user.create({ | ||
| data: { | ||
| clerkId: data.clerkId, | ||
|
|
||
| name: data.name, | ||
|
|
||
| // Prisma expects string | null for optional string fields when | ||
| // exactOptionalPropertyTypes is enabled. | ||
| email: data.email ?? null, | ||
| }, | ||
| }); | ||
| } |
Comment on lines
+8
to
+12
| router.post( | ||
| "/sync", | ||
|
|
||
| authSyncController, | ||
| ); |
Comment on lines
+20
to
+30
| const response = await axios.post( | ||
| "http://localhost:8080/api/v1/auth/sync", | ||
|
|
||
| { | ||
| clerkId: user.id, | ||
|
|
||
| name: user.fullName || "User", | ||
|
|
||
| email: user.primaryEmailAddress?.emailAddress, | ||
| }, | ||
| ); |
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ | ||
| userId: "9eba1881-f6aa-4d0e-a85d-ec67458b8a76", | ||
| userId: localStorage.getItem("userId"), |
|
|
||
| <div className="flex-1 overflow-y-auto overflow-x-hidden relative custom-scrollbar z-0"> | ||
| <div className="p-4 md:p-8 lg:p-10 w-full mx-auto min-h-max max-w-[1600px]"> | ||
| <AuthProvider /> |
Comment on lines
+64
to
+68
| function AuthProvider() { | ||
| useAuthSync(); | ||
|
|
||
| return null; | ||
| } No newline at end of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.