feat: setup and roles
This commit is contained in:
@@ -15,6 +15,7 @@ export enum AuthError {
|
||||
|
||||
export type AuthUser = InferUserFromClient<BetterAuthClientOptions> & {
|
||||
twoFactorEnabled?: boolean | null;
|
||||
role?: string | null;
|
||||
};
|
||||
|
||||
type sessionData = {
|
||||
@@ -35,6 +36,7 @@ export const useAuth = () => {
|
||||
const session = useState<InferSessionFromClient<BetterAuthClientOptions> | null>('auth:session', () => null);
|
||||
const user = useState<AuthUser | null>('auth:user', () => null);
|
||||
const sessionFetching = import.meta.server ? ref(false) : useState('auth:sessionFetching', () => false);
|
||||
const isAdmin = computed(() => user.value?.role === 'admin');
|
||||
|
||||
let sessionPromise: Promise<Result<sessionData, AuthError>> | null = null;
|
||||
|
||||
@@ -244,6 +246,7 @@ export const useAuth = () => {
|
||||
client: authClient,
|
||||
session,
|
||||
user,
|
||||
isAdmin,
|
||||
loggedIn: computed(() => !!session.value),
|
||||
signIn,
|
||||
verifyTwoFactor,
|
||||
|
||||
Reference in New Issue
Block a user