From 3415f41044ce640d065518d0197754fdd0d8e334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Fri, 29 Dec 2023 18:11:51 -0500 Subject: [PATCH] refactor(typing): override "#auth" module from nuxt-auth make it so that we're absolutely sure that the type of `useAuth().data` is interpreted by typescript to be OUR version of `SessionData` --- typings/auth.d.ts | 56 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/typings/auth.d.ts b/typings/auth.d.ts index 460bf04..a722c23 100644 --- a/typings/auth.d.ts +++ b/typings/auth.d.ts @@ -1,10 +1,60 @@ import { IUser } from "@models/user"; -import { SessionData as SDI } from "#auth"; +import { + GetSessionFunc, + SecondarySignInOptions, + SessionLastRefreshedAt, + SessionStatus, + SignInFunc, + SignOutFunc, +} from "@sidebase/nuxt-auth/dist/runtime/types"; +import { ComputedRef, Ref } from "vue"; declare module "#auth" { - export interface SessionData extends SDI { + interface SessionData { token?: string; user?: IUser; } - export type WrappedSessionData = SessionData; } + +declare module "@sidebase/nuxt-auth/dist/runtime/types" { + interface SessionData { + token?: string; + user?: IUser; + } + declare const signIn: SignInFunc; + declare const signOut: SignOutFunc; + declare const getSession: GetSessionFunc; + declare const signUp: ( + credentials: Credentials, + signInOptions?: SecondarySignInOptions, + ) => Promise; + + type WrappedSessionData = Ref; + export interface CommonUseAuthReturn< + SignIn, + SignOut, + GetSession, + SessionData, + > { + data: Readonly>; + lastRefreshedAt: Readonly>; + status: ComputedRef; + signIn: SignIn; + signOut: SignOut; + getSession: GetSession; + } + interface UseAuthReturn + extends CommonUseAuthReturn< + typeof signIn, + typeof signOut, + typeof getSession, + SessionData + > { + signUp: typeof signUp; + token: Readonly>; + } + + export declare const useAuth: () => UseAuthReturn; +} + +export {};