|
| 1 | +import { getProviders } from "next-auth/react"; |
| 2 | +import Link from "next/link"; |
| 3 | +import AuthForm from "../AuthForm"; |
| 4 | +import { getServerSession } from "next-auth"; |
| 5 | +import { authOptions } from "@/app/api/auth/[...nextauth]/AuthOptions"; |
| 6 | +import { redirect } from "next/navigation"; |
| 7 | +import { constructMetadata } from "@/app/utils"; |
| 8 | + |
| 9 | +export const metadata = constructMetadata({ |
| 10 | + description: |
| 11 | + "Login to ScreenLink to start recording demos with your screen and camera.", |
| 12 | + title: "Sign In - ScreenLink", |
| 13 | +}); |
| 14 | + |
| 15 | +export default async function SignIn({ |
| 16 | + searchParams, |
| 17 | +}: { |
| 18 | + searchParams?: { [key: string]: string | string[] | undefined }; |
| 19 | +}) { |
| 20 | + const session = await getServerSession(authOptions); |
| 21 | + |
| 22 | + // If the user is already logged in, redirect. |
| 23 | + // Note: Make sure not to redirect to the same page |
| 24 | + // To avoid an infinite loop! |
| 25 | + if (session) { |
| 26 | + redirect("/app"); |
| 27 | + } |
| 28 | + |
| 29 | + // Get redirect from query |
| 30 | + const redirectTo = searchParams?.redirect |
| 31 | + ? String(searchParams?.redirect) |
| 32 | + : "/app"; |
| 33 | + |
| 34 | + return ( |
| 35 | + <div className="relative max-w-6xl mx-auto px-4 sm:px-6"> |
| 36 | + <div className="pt-32 pb-12 md:pt-40 md:pb-20"> |
| 37 | + {/* Page header */} |
| 38 | + <div className="max-w-3xl mx-auto text-center pb-12"> |
| 39 | + <h1 className="h2 font-hkgrotesk">Welcome back!</h1> |
| 40 | + </div> |
| 41 | + <div className="max-w-sm mx-auto"> |
| 42 | + {/* Social logins */} |
| 43 | + <AuthForm providers={await getProviders()} redirect={redirectTo} /> |
| 44 | + <div className="text-center mt-6"> |
| 45 | + <div className="text-sm text-slate-500"> |
| 46 | + Don't you have an account?{" "} |
| 47 | + <Link className="font-medium text-indigo-500" href="/signup"> |
| 48 | + Get Started |
| 49 | + </Link> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + ); |
| 56 | +} |
0 commit comments