diff --git a/.env b/.env index b7ed28e0..67d490f0 100644 --- a/.env +++ b/.env @@ -1,3 +1,6 @@ # POSTGRES_URL must be set in Vercel environment variables for production. # For local development, add POSTGRES_URL to .env.local instead. # POSTGRES_URL= + +NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in +NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up diff --git a/.env.local.example b/.env.local.example index 41c0f91c..0ff92ba0 100644 --- a/.env.local.example +++ b/.env.local.example @@ -32,3 +32,7 @@ NEXT_PUBLIC_SUPABASE_URL=YOUR_SUPABASE_URL_HERE NEXT_PUBLIC_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY_HERE SUPABASE_SERVICE_ROLE_KEY=YOUR_SUPABASE_SERVICE_ROLE_KEY_HERE DATABASE_URL=postgresql://postgres:[YOUR-POSTGRES-PASSWORD]@[YOUR-SUPABASE-DB-HOST]:[PORT]/postgres + +# Clerk Custom Sign-In/Up URLs +NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in +NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up diff --git a/.gitignore b/.gitignore index 4d43ddd2..d18a1e51 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ aef_index.csv *.log deno.json edge_function/ + +# clerk configuration (can include secrets) +/.clerk/ diff --git a/app/auth/discord/page.tsx b/app/auth/discord/page.tsx new file mode 100644 index 00000000..0c4870c2 --- /dev/null +++ b/app/auth/discord/page.tsx @@ -0,0 +1,50 @@ +'use client' + +import { useEffect, Suspense } from 'react' +import { useSignIn, useUser } from '@clerk/nextjs' +import { useRouter } from 'next/navigation' + +function DiscordAuthRedirect() { + const { signIn } = useSignIn() + const { isSignedIn, isLoaded: isUserLoaded } = useUser() + const isSignInLoaded = !!signIn + const router = useRouter() + + useEffect(() => { + if (isUserLoaded && isSignedIn) { + router.push('/') + return + } + + if (isSignInLoaded && signIn) { + signIn.sso({ + strategy: 'oauth_discord', + redirectCallbackUrl: '/sso-callback', + redirectUrl: '/', + }).catch((err) => { + console.error('Failed to redirect to Discord SSO:', err) + }) + } + }, [isSignInLoaded, signIn, isUserLoaded, isSignedIn, router]) + + return ( +
+
+
+

Redirecting to Discord SSO...

+
+
+ ) +} + +export default function DiscordAuthAliasPage() { + return ( + +
+
+ }> + +
+ ) +} diff --git a/app/discord-auth/page.tsx b/app/discord-auth/page.tsx new file mode 100644 index 00000000..417986e1 --- /dev/null +++ b/app/discord-auth/page.tsx @@ -0,0 +1,50 @@ +'use client' + +import { useEffect, Suspense } from 'react' +import { useSignIn, useUser } from '@clerk/nextjs' +import { useRouter } from 'next/navigation' + +function DiscordAuthRedirect() { + const { signIn } = useSignIn() + const { isSignedIn, isLoaded: isUserLoaded } = useUser() + const isSignInLoaded = !!signIn + const router = useRouter() + + useEffect(() => { + if (isUserLoaded && isSignedIn) { + router.push('/') + return + } + + if (isSignInLoaded && signIn) { + signIn.sso({ + strategy: 'oauth_discord', + redirectCallbackUrl: '/sso-callback', + redirectUrl: '/', + }).catch((err) => { + console.error('Failed to redirect to Discord SSO:', err) + }) + } + }, [isSignInLoaded, signIn, isUserLoaded, isSignedIn, router]) + + return ( +
+
+
+

Redirecting to Discord SSO...

+
+
+ ) +} + +export default function DiscordAuthPage() { + return ( + +
+
+ }> + +
+ ) +} diff --git a/app/layout.tsx b/app/layout.tsx index 9d068e98..c8f4a020 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -77,7 +77,24 @@ export default function RootLayout({ children: React.ReactNode }>) { return ( - +