This commit is contained in:
Emma Ruby 2024-11-24 18:52:12 -06:00
parent f117b6295b
commit 633d830a10
2 changed files with 0 additions and 77 deletions

View File

@ -1,18 +0,0 @@
import { createClient } from '@/lib/supabase/server'
import { NextResponse } from 'next/server'
export async function GET(request: Request) {
const { searchParams, origin } = new URL(request.url)
const code = searchParams.get('code')
const next = searchParams.get('next') ?? '/'
if (code) {
const supabase = createClient()
const { error } = await supabase.auth.exchangeCodeForSession(code)
if (!error) {
return NextResponse.redirect(`${origin}${next}`)
}
}
return NextResponse.redirect(`${origin}/auth/auth-code-error`)
}

View File

@ -1,59 +0,0 @@
"use client"
import { createClient } from '@/lib/supabase/client'
import { Button } from './ui/button'
import { LogIn, LogOut, User } from 'lucide-react'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
export function AuthButton({ user }: { user: any }) {
const supabase = createClient()
const handleSignIn = async () => {
await supabase.auth.signInWithOAuth({
provider: 'vatsim',
options: {
redirectTo: `${location.origin}/auth/callback`,
},
})
}
const handleSignOut = async () => {
await supabase.auth.signOut()
window.location.reload()
}
if (user) {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" className="gap-2">
<User className="h-4 w-4" />
{user.user_metadata?.full_name || 'User'}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Account</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={handleSignOut}>
<LogOut className="h-4 w-4 mr-2" />
Sign Out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}
return (
<Button onClick={handleSignIn} className="gap-2">
<LogIn className="h-4 w-4" />
Sign in with VATSIM
</Button>
)
}