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 080b9c5 commit 6ccdfed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
21 changes: 19 additions & 2 deletions src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,30 @@ 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}`}
}
}
}

const signOut: SignOutFunc = async (signOutOptions) => {
const nuxt = useNuxtApp()
const runtimeConfig = await callWithNuxt(nuxt, useRuntimeConfig)
const config = useTypedBackendConfig(runtimeConfig, 'local')
const { data, rawToken, token } = await callWithNuxt(nuxt, useAuthState)

const headers = new Headers(config.token.headerName ? { [config.token.headerName]: token.value } as HeadersInit : undefined)
const headers = new Headers(addHeaders(token.value, config))
data.value = null
rawToken.value = null

Expand Down Expand Up @@ -80,7 +97,7 @@ const getSession: GetSessionFunc<SessionData | null | void> = async (getSessionO
return
}

const headers = new Headers(token.value && config.token.headerName ? { [config.token.headerName]: token.value } as HeadersInit : undefined)
const headers = new Headers(addHeaders(token.value, config))

loading.value = true
try {
Expand Down
9 changes: 0 additions & 9 deletions src/runtime/composables/local/useAuthState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ export const useAuthState = (): UseAuthStateReturn => {
return null
}

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

Expand Down

0 comments on commit 6ccdfed

Please sign in to comment.