Initial commit v1.1
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { NextResponse, type NextRequest } from 'next/server'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams, origin } = new URL(request.url)
|
||||
const code = searchParams.get('code')
|
||||
const next = searchParams.get('next') ?? '/dashboard'
|
||||
|
||||
if (code) {
|
||||
const supabase = await createClient()
|
||||
const { error } = await supabase.auth.exchangeCodeForSession(code)
|
||||
|
||||
if (!error) {
|
||||
return NextResponse.redirect(`${origin}${next}`)
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.redirect(`${origin}/login?error=auth_failed`)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { createClient } from '@/lib/supabase/client'
|
||||
import { authClient } from '@/lib/auth-client'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
@@ -17,17 +17,13 @@ export default function LoginPage() {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
|
||||
const supabase = createClient()
|
||||
const { error } = await supabase.auth.signInWithOtp({
|
||||
const { error } = await authClient.signIn.magicLink({
|
||||
email,
|
||||
options: {
|
||||
emailRedirectTo: `${window.location.origin}/auth/confirm`,
|
||||
shouldCreateUser: false, // invite-only: only existing users can log in
|
||||
},
|
||||
callbackURL: '/dashboard',
|
||||
})
|
||||
|
||||
if (error) {
|
||||
setError(error.message)
|
||||
setError(error.message ?? 'Could not send link. Have you been invited?')
|
||||
} else {
|
||||
setSubmitted(true)
|
||||
}
|
||||
@@ -41,8 +37,7 @@ export default function LoginPage() {
|
||||
<div className="text-4xl">⛳</div>
|
||||
<h1 className="text-2xl font-bold">Check your email</h1>
|
||||
<p className="text-muted-foreground">
|
||||
We sent a magic link to <strong>{email}</strong>. Tap the link to
|
||||
sign in.
|
||||
We sent a magic link to <strong>{email}</strong>. Tap it to sign in.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -72,9 +67,7 @@ export default function LoginPage() {
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && <p className="text-destructive text-sm">{error}</p>}
|
||||
|
||||
{error && <p className="text-sm text-destructive">{error}</p>}
|
||||
<Button type="submit" className="w-full" disabled={loading}>
|
||||
{loading ? 'Sending…' : 'Send magic link'}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user