Skip to content

Commit

Permalink
fix: improved nullable schema fields
Browse files Browse the repository at this point in the history
  • Loading branch information
manchenkoff committed Aug 30, 2024
1 parent ee12044 commit 879fdee
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/runtime/composables/useSanctumAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const useSanctumAuth = <T>(): SanctumAuth<T> => {
})

async function refreshIdentity() {
user.value = await client<T>(options.endpoints.user)
user.value = await client<T>(options.endpoints.user!)
}

/**
Expand Down Expand Up @@ -65,7 +65,7 @@ export const useSanctumAuth = <T>(): SanctumAuth<T> => {
)
}

const response = await client<TokenResponse>(options.endpoints.login, {
const response = await client<TokenResponse>(options.endpoints.login!, {
method: 'post',
body: credentials,
})
Expand Down Expand Up @@ -111,7 +111,7 @@ export const useSanctumAuth = <T>(): SanctumAuth<T> => {
const currentRoute = useRoute()
const currentPath = trimTrailingSlash(currentRoute.path)

await client(options.endpoints.logout, { method: 'post' })
await client(options.endpoints.logout!, { method: 'post' })

user.value = null

Expand Down
8 changes: 4 additions & 4 deletions src/runtime/interceptors/cookie/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function initCsrfCookie(
config: ModuleOptions,
logger: ConsolaInstance,
): Promise<void> {
await $fetch(config.endpoints.csrf, {
await $fetch(config.endpoints.csrf!, {
baseURL: config.baseUrl,
credentials: 'include',
})
Expand All @@ -65,12 +65,12 @@ async function useCsrfHeader(
config: ModuleOptions,
logger: ConsolaInstance,
): Promise<HeadersInit> {
let csrfToken = useCookie(config.csrf.cookie, COOKIE_OPTIONS)
let csrfToken = useCookie(config.csrf.cookie!, COOKIE_OPTIONS)

if (!csrfToken.value) {
await initCsrfCookie(config, logger)

csrfToken = useCookie(config.csrf.cookie, COOKIE_OPTIONS)
csrfToken = useCookie(config.csrf.cookie!, COOKIE_OPTIONS)
}

if (!csrfToken.value) {
Expand All @@ -86,7 +86,7 @@ async function useCsrfHeader(
return {
...headers,
...(csrfToken.value && {
[config.csrf.header]: csrfToken.value,
[config.csrf.header!]: csrfToken.value,
}),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/middleware/sanctum.auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RouteLocationRaw } from 'vue-router'
import type { RouteLocationAsPathGeneric } from 'vue-router'
import { useSanctumConfig } from '../composables/useSanctumConfig'
import { useSanctumAuth } from '../composables/useSanctumAuth'
import { trimTrailingSlash } from '../utils/formatter'
Expand All @@ -18,7 +18,7 @@ export default defineNuxtRouteMiddleware((to) => {
throw createError({ statusCode: 403 })
}

const redirect: RouteLocationRaw = { path: endpoint }
const redirect: RouteLocationAsPathGeneric = { path: endpoint! }

if (options.redirect.keepRequestedRoute) {
redirect.query = { redirect: trimTrailingSlash(to.fullPath) }
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/middleware/sanctum.global.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RouteLocationRaw } from 'vue-router'
import type { RouteLocationAsPathGeneric } from 'vue-router'
import { useSanctumConfig } from '../composables/useSanctumConfig'
import { useSanctumAuth } from '../composables/useSanctumAuth'
import { trimTrailingSlash } from '../utils/formatter'
Expand Down Expand Up @@ -52,7 +52,7 @@ export default defineNuxtRouteMiddleware((to) => {
return
}

const redirect: RouteLocationRaw = { path: loginPage }
const redirect: RouteLocationAsPathGeneric = { path: loginPage! }

if (options.redirect.keepRequestedRoute) {
redirect.query = { redirect: trimTrailingSlash(to.fullPath) }
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default defineNuxtPlugin(async () => {

try {
logger.debug('Fetching user identity on plugin initialization')
user.value = await client(options.endpoints.user)
user.value = await client(options.endpoints.user!)
}
catch (error) {
handleIdentityLoadError(error as Error, logger)
Expand Down
10 changes: 5 additions & 5 deletions src/runtime/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,23 @@ export interface ModuleOptions {
/**
* Laravel Sanctum endpoints to be used by the client.
*/
endpoints: SanctumEndpoints
endpoints: Partial<SanctumEndpoints>
/**
* CSRF token specific options.
*/
csrf: CsrfOptions
csrf: Partial<CsrfOptions>
/**
* OFetch client specific options.
*/
client: ClientOptions
client: Partial<ClientOptions>
/**
* Behavior of the plugin redirects when user is authenticated or not.
*/
redirect: RedirectOptions
redirect: Partial<RedirectOptions>
/**
* Behavior of the global middleware.
*/
globalMiddleware: GlobalMiddlewareOptions
globalMiddleware: Partial<GlobalMiddlewareOptions>
/**
* The log level to use for the logger.
*
Expand Down

0 comments on commit 879fdee

Please sign in to comment.