safak / full-stack-school

111 stars 103 forks source link

After login, blank page #2

Open bs-prashant-gautam opened 1 week ago

bs-prashant-gautam commented 1 week ago

Created a user with role admin exacly as shown in video, but still after login, it just shows blank page.

Gdoor777 commented 1 week ago

same here, lama-dev-next-dashboard@0.1.0 dev

next dev

⚠ Port 3000 is in use, trying 3001 instead. ⚠ Port 3001 is in use, trying 3002 instead. ⚠ Port 3002 is in use, trying 3003 instead. ▲ Next.js 14.2.5

Gdoor777 commented 1 week ago

I had to change the middleware to this: import { clerkMiddleware } from '@clerk/nextjs/server'; import { NextResponse } from 'next/server'; import { routeAccessMap } from './lib/settings'; import { createRouteMatcher } from '@clerk/nextjs/server';

const matchers = Object.keys(routeAccessMap).map((route) => ({ matcher: createRouteMatcher([route]), allowedRoles: routeAccessMap[route], }));

export default clerkMiddleware((auth, req) => { const { sessionClaims } = auth();

// Access public metadata from sessionClaims const publicMetadata = sessionClaims?.['https://clerk.dev/user_public_metadata'] as { role?: string; };

// Extract the role from public metadata const role = publicMetadata?.role || 'guest';

console.log('Extracted Role:', role);

// Implement role-based access control for (const { matcher, allowedRoles } of matchers) { if (matcher(req) && !allowedRoles.includes(role)) { console.log( Access denied for role '${role}' on route '${req.nextUrl.pathname}' ); if (role === 'guest') { return NextResponse.redirect(new URL('/no-role', req.url)); } return NextResponse.redirect(new URL(/${role}, req.url)); } } });

export const config = { matcher: ['/((?!_next|[^?]\.(?:.)).*)'], };

codelasak commented 1 week ago

Did you configuration on clerk? Follow this : https://youtu.be/6sfiAyKy8Jo?t=7925

otabek-olimjonov commented 1 week ago

I also got the same error. is there anybody who fixed that issue?

arbi-jridi commented 6 days ago

Same here , i configure the roles in clerk but i got a blank page , and undefined role !

arbi-jridi commented 4 days ago

Guys i fixed by adding : { "metadata": "{{user.public_metadata}}" }

in Customize session token in clerk dashboard , now everything works good image_2024-09-26_135621033

loggy7 commented 1 day ago

It not work for me

loggy7 commented 1 day ago

It doesn't work for me