Open History to see the last commit
1import { useState, useEffect, Suspense } from 'react'
2import { createFileRoute, redirect } from '@tanstack/react-router'
3β
4export const Route = createFileRoute('/login')({
5 beforeLoad: ({ context }) => {
6 // Redirect if already authenticated
7 if (context.session) {
8 throw redirect({ to: '/' })
9 }
10 },
11 component: Login,
12})
13β
14function Login() {
15 const [csrfToken, setCsrfToken] = useState<string>('')
16β
17 useEffect(() => {
18 fetch('/api/auth/csrf')
19 .then((res) => res.json())
20 .then((data) => setCsrfToken(data.csrfToken))
21 }, [])
22β
23 return (
24 <div className="max-w-md mx-auto mt-10">
25 <h1 className="text-2xl font-bold mb-6 text-center">Sign In</h1>
26β
27 <div className="space-y-4">
28 <form action="/api/auth/signin/auth0" method="POST">
29 <input type="hidden" name="csrfToken" value={csrfToken} />
30 <input type="hidden" name="callbackUrl" value="/" />
31 <button
32 type="submit"
33 className="w-full flex items-center justify-center gap-3 px-4 py-3 bg-orange-500 text-white rounded-lg hover:bg-orange-600 transition-colors cursor-pointer"
34 >
35 <svg className="w-5 h-5" viewBox="0 0 24 24" fill="currentColor">
36 <path d="M21.98 7.448L19.62 0H4.347L2.02 7.448c-1.352 4.312.03 9.206 3.815 12.015L12.007 24l6.157-4.552c3.755-2.81 5.182-7.688 3.815-12.015l-6.16 4.58 2.343 7.45-6.157-4.597-6.158 4.58 2.358-7.433-6.188-4.55 7.63-.045L12.008 0l2.356 7.404 7.615.044z" />
37 </svg>
38 Continue with Auth0
39 </button>
40 </form>
41β
42 <p className="text-center text-sm text-gray-500 mt-4">
43 You'll be redirected to Auth0 to complete the sign-in process.
44 </p>
45 </div>
46 </div>
47 )
48}