-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
import { User } from '@supabase/supabase-js'; | ||
import { User as SupabaseUser } from '@supabase/supabase-js'; | ||
|
||
export enum UserRole { | ||
AUTHENTICATED = 'authenticated', | ||
SERVICE_ROLE = 'service_role', | ||
ANON = 'anon', // Anonymous | ||
} | ||
|
||
export type User = SupabaseUser; | ||
|
||
export interface AnonymousUser extends User { | ||
role: UserRole.ANON; | ||
is_anonymous: true; | ||
} | ||
|
||
export interface AuthenticatedUser extends User { | ||
role: UserRole; | ||
role: UserRole.AUTHENTICATED; | ||
is_anonymous: false; | ||
} | ||
|
||
export function isAnonymousUser(user: User | null): user is AnonymousUser { | ||
return user?.role === UserRole.ANON && user.is_anonymous === true; | ||
} | ||
|
||
export function isAuthenticatedUser( | ||
user: User | null | ||
): user is AuthenticatedUser { | ||
return user?.role === UserRole.AUTHENTICATED && user.is_anonymous === false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters