got auth working on /profile

This commit is contained in:
Genuinely 2025-03-25 23:42:23 -07:00
parent e7ff02f1b8
commit 23870f485d
8 changed files with 106 additions and 154 deletions

View file

@ -1,4 +0,0 @@
// pages/api/auth/[...auth0].ts
import { handleAuth } from '@auth0/nextjs-auth0';
export default handleAuth();

View file

@ -5,7 +5,6 @@ import { cn } from '@/lib/utils';
import Sidebar from '@/components/Sidebar';
import { Toaster } from 'sonner';
import ThemeProvider from '@/components/theme/Provider';
import { UserProvider } from '@auth0/nextjs-auth0/client'; // ✅ Auth0 wrapper
const montserrat = Montserrat({
weight: ['300', '400', '500', '700'],
@ -28,21 +27,19 @@ export default function RootLayout({
return (
<html className="h-full" lang="en" suppressHydrationWarning>
<body className={cn('h-full', montserrat.className)}>
<UserProvider> {/* ✅ Wrap app in Auth0 context */}
<ThemeProvider>
<Sidebar>{children}</Sidebar>
<Toaster
toastOptions={{
unstyled: true,
classNames: {
toast:
'bg-light-primary dark:bg-dark-secondary dark:text-white/70 text-black-70 rounded-lg p-4 flex flex-row items-center space-x-2',
},
}}
/>
</ThemeProvider>
</UserProvider>
<ThemeProvider>
<Sidebar>{children}</Sidebar>
<Toaster
toastOptions={{
unstyled: true,
classNames: {
toast:
'bg-light-primary dark:bg-dark-secondary dark:text-white/70 text-black-70 rounded-lg p-4 flex flex-row items-center space-x-2',
},
}}
/>
</ThemeProvider>
</body>
</html>
);
}
}

24
src/app/profile/page.tsx Normal file
View file

@ -0,0 +1,24 @@
import { auth0 } from '@/lib/auth0';
export default async function ProfilePage() {
const session = await auth0.getSession();
if (!session) {
return (
<main>
<h2> Not logged in</h2>
<a href="/auth/login">Log in</a>
</main>
);
}
return (
<main>
<h2> Logged in as {session.user.name}</h2>
<p>Email: {session.user.email}</p>
<img src={session.user.picture} alt="avatar" width={100} />
<br />
<a href="/auth/logout">Log out</a>
</main>
);
}

6
src/lib/auth0.ts Normal file
View file

@ -0,0 +1,6 @@
// lib/auth0.ts
import { Auth0Client } from '@auth0/nextjs-auth0/server';
export const auth0 = new Auth0Client();
console.log('💥 AUTH0_ISSUER_BASE_URL =', process.env.AUTH0_ISSUER_BASE_URL);

19
src/middleware.ts Normal file
View file

@ -0,0 +1,19 @@
import type { NextRequest } from "next/server"
import { auth0 } from "./lib/auth0"
export async function middleware(request: NextRequest) {
return await auth0.middleware(request)
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico, sitemap.xml, robots.txt (metadata files)
*/
"/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
],
}