feat: add Auth0 passwordless login

This commit is contained in:
Riccardo
2024-06-25 21:50:16 +02:00
parent 8f60f0b139
commit 35fa565d0a
8 changed files with 178 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
import { handleAuth } from '@auth0/nextjs-auth0';
export const GET = handleAuth();

View File

@@ -1,3 +1,4 @@
import { UserProvider } from '@auth0/nextjs-auth0/client';
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import './globals.css';
@@ -16,7 +17,9 @@ export default function RootLayout({
}>) {
return (
<html lang='en'>
<body className={inter.className}>{children}</body>
<UserProvider>
<body className={inter.className}>{children}</body>
</UserProvider>
</html>
);
}

8
app/login/page.tsx Normal file
View File

@@ -0,0 +1,8 @@
export default function SignIn() {
return (
<div>
<a href='/api/auth/login'>Login</a>
<a href='/api/auth/logout'>Logout</a>
</div>
);
}

18
app/user/page.tsx Normal file
View File

@@ -0,0 +1,18 @@
'use client';
import { useUser } from '@auth0/nextjs-auth0/client';
export default function ProfileClient() {
const { user, error, isLoading } = useUser();
if (isLoading) return <div>Loading...</div>;
if (error) return <div>{error.message}</div>;
return (
user && (
<div>
<p>{user.email}</p>
</div>
)
);
}