Skip to content

Commit

Permalink
chore: extracted default module options
Browse files Browse the repository at this point in the history
  • Loading branch information
manchenkoff committed May 30, 2024
1 parent 16cdde6 commit e0f2c7a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
31 changes: 31 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { SanctumModuleOptions } from './runtime/types';

export const defaultModuleOptions: Partial<SanctumModuleOptions> = {
userStateKey: 'sanctum.user.identity',
redirectIfAuthenticated: false,
endpoints: {
csrf: '/sanctum/csrf-cookie',
login: '/login',
logout: '/logout',
user: '/api/user',
},
csrf: {
cookie: 'XSRF-TOKEN',
header: 'X-XSRF-TOKEN',
},
client: {
retry: false,
},
redirect: {
keepRequestedRoute: false,
onLogin: '/',
onLogout: '/',
onAuthOnly: '/login',
onGuestOnly: '/',
},
globalMiddleware: {
enabled: false,
allow404WithoutAuth: true,
},
logLevel: 3,
};
31 changes: 2 additions & 29 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@nuxt/kit';
import { defu } from 'defu';
import type { SanctumModuleOptions } from './runtime/types';
import { defaultModuleOptions } from './config';

type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
Expand All @@ -24,35 +25,7 @@ export default defineNuxtModule<DeepPartial<SanctumModuleOptions>>({
},
},

defaults: {
userStateKey: 'sanctum.user.identity',
redirectIfAuthenticated: false,
endpoints: {
csrf: '/sanctum/csrf-cookie',
login: '/login',
logout: '/logout',
user: '/api/user',
},
csrf: {
cookie: 'XSRF-TOKEN',
header: 'X-XSRF-TOKEN',
},
client: {
retry: false,
},
redirect: {
keepRequestedRoute: false,
onLogin: '/',
onLogout: '/',
onAuthOnly: '/login',
onGuestOnly: '/',
},
globalMiddleware: {
enabled: false,
allow404WithoutAuth: true,
},
logLevel: 3,
},
defaults: defaultModuleOptions,

setup(options, nuxt) {
const resolver = createResolver(import.meta.url);
Expand Down

0 comments on commit e0f2c7a

Please sign in to comment.