Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
benjipott committed Dec 5, 2023
1 parent dd32063 commit 28016db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
25 changes: 9 additions & 16 deletions src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { callWithNuxt } from '#app/nuxt'
import { readonly, Ref } from 'vue'
import { jsonPointerGet, useTypedBackendConfig } from '../../helpers'
import { CommonUseAuthReturn, GetSessionFunc, SecondarySignInOptions, SignInFunc, SignOutFunc } from '../../types'
import { getRequestURLWN } from '../../utils/callWithNuxt'
import { _fetch } from '../../utils/fetch'
import { useAuthState } from './useAuthState'
import { callWithNuxt } from '#app/nuxt'
// @ts-expect-error - #auth not defined
import type { SessionData } from '#auth'
import { navigateTo, nextTick, useNuxtApp, useRuntimeConfig } from '#imports'
Expand Down Expand Up @@ -43,21 +43,20 @@ const signIn: SignInFunc<Credentials, any> = async (credentials, signInOptions,
}
}


const addHeaders = (token: string | null, config: ReturnType<typeof useTypedBackendConfig>) => {
if (!(token && config.token.headerName)) {
return undefined
}

if (config.token.type.length > 0) {
switch (config.token.type) {
case 'Cookie':
return { [config.token.headerName]: `${config.token.name}=${token}` }
case 'Bearer':
default:
return { [config.token.headerName]: `${config.token.type} ${token}`}
}
switch (config.token.type) {
case 'Cookie':
return { [config.token.headerName]: `${config.token.name}=${token}` }
case 'Bearer':
default:
return { [config.token.headerName]: `${config.token.type} ${token}` }
}
}
}

const signOut: SignOutFunc = async (signOutOptions) => {
Expand Down Expand Up @@ -131,13 +130,7 @@ const signUp = async (credentials: Credentials, signInOptions?: SecondarySignInO
body: credentials
})

await nextTick(getSession)

const { callbackUrl, redirect = true, external } = signInOptions ?? {}
if (redirect) {
const urlToNavigateTo = callbackUrl ?? await getRequestURLWN(nuxt)
return navigateTo(urlToNavigateTo, { external })
}
return signIn(credentials, signInOptions)
}

interface UseAuthReturn extends CommonUseAuthReturn<typeof signIn, typeof signOut, typeof getSession, SessionData> {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/local/useAuthState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useAuthState = (): UseAuthStateReturn => {
const commonAuthState = makeCommonAuthState<SessionData>()

// Re-construct state from cookie, also setup a cross-component sync via a useState hack, see https://github.com/nuxt/nuxt/issues/13020#issuecomment-1397282717
const _rawTokenCookie = useCookie<string | null>(config.token.name, { default: () => null, maxAge: config.token.maxAgeInSeconds, sameSite: config.token.sameSiteAttribute, secure: config.token.secure, domain: config.token.domain })
const _rawTokenCookie = useCookie<string | null>(config.token.name, { default: config.token.default, maxAge: config.token.maxAgeInSeconds, sameSite: config.token.sameSiteAttribute, secure: config.token.secure, domain: config.token.domain })

const rawToken = useState('auth:raw-token', () => _rawTokenCookie.value)
watch(rawToken, () => { _rawTokenCookie.value = rawToken.value })
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ type ProviderLocal = {
* @default auth:token Access the cookie `auth:token` from session
*/
name?: string,

default?: () => string | null
/**
* How to extract the authentication-token from the sign-in response.
*
Expand Down Expand Up @@ -179,7 +181,7 @@ type ProviderLocal = {
* @default undefined use
* @example 'domain.com'
*/
domain?: boolean,
domain?: string,

},
/**
Expand Down

0 comments on commit 28016db

Please sign in to comment.