Skip to content

Commit

Permalink
fix: types and bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
LorexIQ committed Dec 7, 2023
1 parent abd9542 commit eb7b18c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ export default defineNuxtConfig({
//modules: ['nuxt-local-auth'],

localAuth: {
origin: 'https://catman-dev.atrinix.ruf/api/v1/',
origin: 'https://catman-dev.atrinix.ru/api/v1/',
token: {
lifetime: 60 * 60 * 24,
path: 'access',
queryKey: 'token'
},
sessions: {
path: 'data',
refreshEvery: 5000
},
refreshToken: {
Expand Down
1 change: 1 addition & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineNuxtModule<ModuleOptions>({
defaults: {
origin: '',
sessions: {
path: undefined,
refreshEvery: undefined,
cookiePrefix: 'localAuth',
},
Expand Down
8 changes: 6 additions & 2 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ export default defineNuxtPlugin(async () => {

try {
if (options.token.queryKey) await checkAndSaveQueryAuth();
} catch (e) {}
} catch (e) {
console.error(e);
}
try {
if (token.value) await getMe();
} catch (e) {}
} catch (e) {
console.error(e);
}

if (options.sessions.refreshEvery) {
watch(meta, value => {
Expand Down
9 changes: 8 additions & 1 deletion src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface UseLocalAuthReturn extends UseLocalAuthReturnData, UseLocalAuth
export interface UseLocalAuthReturnData {
data: ComputedRef<UseLocalAuthCredentials>;
meta: Ref<UseLocalAuthSession>;
origin: string;
token: ComputedRef<string | null>;
}
export interface UseLocalAuthReturnMethods {
Expand Down Expand Up @@ -66,6 +67,12 @@ export interface ModuleOptions {
pages: ModuleOptionsPages;
}
interface ModuleOptionsSession {
/* Path to session data. Default: undefined
* Example #1: { ... } > value: undefined
* Example #2: { data: ... } > value: 'data'
* Example #2: { data: { user: ... } } > value: 'data/user'
* */
path?: string;
/* Enabled refresh user data every N ms. Default: undefined
* Example: one getMe request in 5 seconds. value > 5000
* Example: disable refresh. value > undefined
Expand Down Expand Up @@ -149,7 +156,7 @@ interface ModuleOptionsPages {
* */
serverIsDown?: string;
/* Protecting all pages from guests. Default: false */
protectAllPages?: boolean
protectAllPages?: boolean;
}
interface ModuleOptionsEndpointConfig {
path: string;
Expand Down

0 comments on commit eb7b18c

Please sign in to comment.