@light-auth/nuxt
Version:
light auth framework for nuxt, using arctic
28 lines (27 loc) • 2.07 kB
TypeScript
import { type LightAuthConfig, type LightAuthSession, type LightAuthUser } from "@light-auth/core/client";
import { type Ref } from "vue";
/** Represents the result of a Nuxt useFetch operation*/
export interface FetchResult<T> {
data: Ref<T>;
pending: Ref<boolean>;
error: Ref<any | null>;
status: Ref<AsyncDataRequestStatus>;
refresh: () => Promise<void>;
clear: () => void;
}
export type AsyncDataRequestStatus = "idle" | "pending" | "success" | "error";
export declare function createCustomFetch<T>(key: string, fetcher: () => Promise<T | null>): FetchResult<T | null>;
export declare const createGetAuthSession: <Session extends LightAuthSession = LightAuthSession, User extends LightAuthUser<Session> = LightAuthUser<Session>>(config: LightAuthConfig<Session, User>) => () => FetchResult<Session | null>;
export declare const createSetAuthSession: <Session extends LightAuthSession = LightAuthSession, User extends LightAuthUser<Session> = LightAuthUser<Session>>(config: LightAuthConfig<Session, User>) => (session: Session) => Promise<Session | null>;
export declare const createSetUser: <Session extends LightAuthSession = LightAuthSession, User extends LightAuthUser<Session> = LightAuthUser<Session>>(config: LightAuthConfig<Session, User>) => (user: User) => Promise<User | null>;
type LightAuthConfigClient = Pick<LightAuthConfig<LightAuthSession, LightAuthUser<LightAuthSession>>, "basePath" | "env">;
export declare function CreateLightAuthClient<Session extends LightAuthSession = LightAuthSession, User extends LightAuthUser<Session> = LightAuthUser<Session>>(config?: LightAuthConfigClient | undefined): {
basePath: string;
useSession: () => FetchResult<Session | null>;
setSession: (session: Session) => Promise<Session | null>;
setUser: (user: User) => Promise<User | null>;
useUser: (providerUserId?: string) => FetchResult<User | null>;
signIn: (providerName?: string, callbackUrl?: string) => Promise<void>;
signOut: (revokeToken?: boolean, callbackUrl?: string) => Promise<void>;
};
export {};