-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
199dd95
commit 910f3c4
Showing
4 changed files
with
103 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createClient } from '@/utils/supabase/server' | ||
import { NextResponse } from 'next/server' | ||
import { cookies } from 'next/headers' | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams, origin } = new URL(request.url) | ||
const code = searchParams.get('code') | ||
// if "next" is in param, use it as the redirect URL | ||
const next = searchParams.get('next') ?? '/' | ||
|
||
if (code) { | ||
const supabase = createClient() | ||
const cookieStore = cookies() | ||
|
||
const { error } = await supabase.auth.exchangeCodeForSession(code) | ||
|
||
if (!error) { | ||
const forwardedHost = request.headers.get('x-forwarded-host') // original origin before load balancer | ||
const isLocalEnv = process.env.NODE_ENV === 'development' | ||
if (isLocalEnv) { | ||
// we can be sure that there is no load balancer in between, so no need to watch for X-Forwarded-Host | ||
return NextResponse.redirect(`${origin}${next}`) | ||
} else if (forwardedHost) { | ||
return NextResponse.redirect(`https://${forwardedHost}${next}`) | ||
} else { | ||
return NextResponse.redirect(`${origin}${next}`) | ||
} | ||
} | ||
} | ||
|
||
// return the user to an error page with some instructions | ||
return NextResponse.redirect(`${origin}/auth?error=Could not authenticate user`) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createClient } from '@/utils/supabase/client' | ||
import { useRouter } from 'next/navigation' | ||
import { FaDiscord } from 'react-icons/fa' | ||
|
||
export default function DiscordSignIn() { | ||
const supabase = createClient() | ||
const router = useRouter() | ||
|
||
const handleSignIn = async () => { | ||
const { error } = await supabase.auth.signInWithOAuth({ | ||
provider: 'discord', | ||
options: { | ||
redirectTo: `${location.origin}/auth/callback`, | ||
}, | ||
}) | ||
|
||
if (error) { | ||
console.error('Error signing in with Discord:', error) | ||
} | ||
} | ||
|
||
return ( | ||
<button | ||
onClick={handleSignIn} | ||
className="flex items-center justify-center w-full px-4 py-2 text-sm font-medium text-white bg-[#5865F2] hover:bg-[#4752C4] rounded-md transition-colors duration-300" | ||
> | ||
<FaDiscord className="mr-2 h-4 w-4" /> | ||
Sign in with Discord | ||
</button> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createClient } from '@/utils/supabase/client' | ||
import { useRouter } from 'next/navigation' | ||
import { FcGoogle } from 'react-icons/fc' | ||
|
||
export default function GoogleSignIn() { | ||
const router = useRouter() | ||
const supabase = createClient() | ||
|
||
const handleGoogleSignIn = async () => { | ||
const { error } = await supabase.auth.signInWithOAuth({ | ||
provider: 'google', | ||
options: { | ||
redirectTo: `${location.origin}/auth/callback` | ||
} | ||
}) | ||
|
||
if (error) { | ||
console.error('Error signing in with Google:', error) | ||
} | ||
} | ||
|
||
return ( | ||
<button | ||
onClick={handleGoogleSignIn} | ||
className="flex items-center justify-center w-full px-4 py-2 mt-4 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-neon-green" | ||
> | ||
<FcGoogle className="w-5 h-5 mr-2" /> | ||
Sign in with Google | ||
</button> | ||
) | ||
} |
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