File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ export const profiles = pgTable("profiles", {
66 id : uuid ( "id" ) . primaryKey ( ) ,
77 firstName : text ( "first_name" ) ,
88 lastName : text ( "last_name" ) ,
9- avatarUrl : text ( "avatar_url" ) ,
109 stripeCustomerId : text ( "stripe_customer_id" ) ,
1110 role : userRoleEnum ( "role" ) . default ( "user" ) . notNull ( ) ,
1211 createdAt : timestamp ( "created_at" ) . defaultNow ( ) ,
Original file line number Diff line number Diff line change 1+ export const ROLES = {
2+ ADMIN : "admin" ,
3+ COACH : "coach" ,
4+ USER : "user" ,
5+ } as const ;
6+
7+ export type Role = ( typeof ROLES ) [ keyof typeof ROLES ] ;
Original file line number Diff line number Diff line change 11import { createServerClient } from "@supabase/ssr" ;
22import { type NextRequest , NextResponse } from "next/server" ;
3+ import { ROLES } from "@/lib/roles" ;
34
45export async function updateSession ( request : NextRequest ) {
56 let supabaseResponse = NextResponse . next ( {
@@ -46,8 +47,9 @@ export async function updateSession(request: NextRequest) {
4647
4748 // Protect /dashboard/* — admin only
4849 if ( request . nextUrl . pathname . startsWith ( "/dashboard" ) ) {
49- const role = user ?. app_metadata ?. role ;
50- if ( role !== "admin" ) {
50+ const { data : claimsData } = await supabase . auth . getClaims ( ) ;
51+ const role = claimsData ?. claims ?. user_role ;
52+ if ( role !== ROLES . ADMIN ) {
5153 const url = request . nextUrl . clone ( ) ;
5254 url . pathname = "/" ;
5355 return NextResponse . redirect ( url ) ;
You can’t perform that action at this time.
0 commit comments