-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(header): fetch data more fluently & hide join button when user ex…
…ists
- Loading branch information
Showing
4 changed files
with
51 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,17 @@ | ||
import { db } from '@/db'; | ||
import { members } from '@/db/schema'; | ||
import { memberTable } from '@/db/schema'; | ||
import { currentUser } from '@clerk/nextjs'; | ||
import { eq } from 'drizzle-orm'; | ||
|
||
export async function GET(request: Request) { | ||
export async function GET() { | ||
const user = await currentUser(); | ||
if (!user) { | ||
return new Response(null, { status: 401 }); | ||
} | ||
|
||
try { | ||
const existingUser = await db | ||
.select({ | ||
id: members.id, | ||
}) | ||
.from(members) | ||
.where(eq(members.clerkId, user.id)); | ||
|
||
if (existingUser.length > 0) { | ||
return new Response(JSON.stringify({ exists: true }), { status: 200 }); | ||
} else { | ||
return new Response(JSON.stringify({ exists: false }), { status: 404 }); | ||
} | ||
} catch (error) { | ||
console.error('Error checking user existence:', error); | ||
return new Response(null, { status: 500 }); | ||
} | ||
const existingUser = await db | ||
.select({ id: memberTable.id }) | ||
.from(memberTable) | ||
.where(eq(memberTable.clerkId, user.id)); | ||
return Response.json({ exists: existingUser.length > 0 }); | ||
} |
This file contains 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
This file contains 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
This file contains 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