implement auth error page and moved auth-related pages to /auth path
This commit is contained in:
31
src/app/auth/error/page.tsx
Normal file
31
src/app/auth/error/page.tsx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
|
import Link from "next/link"
|
||||||
|
import { useSearchParams } from "next/navigation"
|
||||||
|
|
||||||
|
export default function AuthErrorPage() {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const errorMessage = searchParams.get('error')
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex items-center justify-center bg-background p-4">
|
||||||
|
<Card className="w-full max-w-md bg-red-400 dark:bg-red-600">
|
||||||
|
<CardHeader className="text-center">
|
||||||
|
<CardTitle className="text-2xl font-bold">Error</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<div className="text-center p-3 bg-background rounded-lg">
|
||||||
|
{errorMessage}
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row">
|
||||||
|
<Button variant="secondary" asChild>
|
||||||
|
<Link href="/">Go back to Homepage</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import Link from "next/link"
|
|||||||
|
|
||||||
export default async function SignInPage() {
|
export default async function SignInPage() {
|
||||||
const session = await auth()
|
const session = await auth()
|
||||||
|
|
||||||
// If already signed in, redirect to home
|
// If already signed in, redirect to home
|
||||||
if (session?.user) {
|
if (session?.user) {
|
||||||
redirect("/")
|
redirect("/")
|
||||||
@@ -32,7 +32,7 @@ export default async function SignInPage() {
|
|||||||
Continue with Authentik
|
Continue with Authentik
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<Link href="/" className="text-sm text-muted-foreground hover:underline">
|
<Link href="/" className="text-sm text-muted-foreground hover:underline">
|
||||||
Continue without signing in
|
Continue without signing in
|
||||||
@@ -42,4 +42,4 @@ export default async function SignInPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -32,9 +32,9 @@ export default function SignIn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => router.push("/signin")}
|
onClick={() => router.push("/auth/signin")}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
Sign In
|
Sign In
|
||||||
|
|||||||
@@ -143,13 +143,13 @@ export default function HomePage() {
|
|||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ prompt: aiPrompt })
|
body: JSON.stringify({ prompt: aiPrompt })
|
||||||
})
|
})
|
||||||
|
|
||||||
if (res.status === 401) {
|
if (res.status === 401) {
|
||||||
alert('Please sign in to use AI features.')
|
alert('Please sign in to use AI features.')
|
||||||
setAiLoading(false)
|
setAiLoading(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
|
|
||||||
if (Array.isArray(data) && data.length > 0) {
|
if (Array.isArray(data) && data.length > 0) {
|
||||||
@@ -254,7 +254,7 @@ export default function HomePage() {
|
|||||||
Sign in to unlock AI-powered calendar features
|
Sign in to unlock AI-powered calendar features
|
||||||
</div>
|
</div>
|
||||||
<Button variant="outline" size="sm" asChild>
|
<Button variant="outline" size="sm" asChild>
|
||||||
<a href="/signin">Sign In</a>
|
<a href="/auth/signin">Sign In</a>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -25,9 +25,11 @@ const config = {
|
|||||||
adapter: DrizzleAdapter(db),
|
adapter: DrizzleAdapter(db),
|
||||||
providers,
|
providers,
|
||||||
pages: {
|
pages: {
|
||||||
signIn: "/signin",
|
signIn: "/auth/signin",
|
||||||
signOut: "/signout",
|
signOut: "/auth/signout",
|
||||||
|
error: "/auth/error",
|
||||||
},
|
},
|
||||||
trustHost: true,
|
trustHost: true,
|
||||||
} satisfies NextAuthConfig;
|
} satisfies NextAuthConfig;
|
||||||
export const { handlers, signIn, signOut, auth }: NextAuthResult = NextAuth(config);
|
export const { handlers, signIn, signOut, auth }: NextAuthResult =
|
||||||
|
NextAuth(config);
|
||||||
|
|||||||
Reference in New Issue
Block a user