Skip to content

Commit

Permalink
added option to define external url
Browse files Browse the repository at this point in the history
  • Loading branch information
zoey-kaiser committed Oct 23, 2023
1 parent b5433a0 commit f4295d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const signIn: SignInFunc<Credentials, any> = async (credentials, signInOptions,

await nextTick(getSession)

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

Expand All @@ -57,9 +57,9 @@ const signOut: SignOutFunc = async (signOutOptions) => {

const res = await _fetch(nuxt, path, { method, headers })

const { callbackUrl, redirect = true } = signOutOptions ?? {}
const { callbackUrl, redirect = true, external } = signOutOptions ?? {}
if (redirect) {
await navigateTo(callbackUrl ?? await getRequestURLWN(nuxt), { external: true })
await navigateTo(callbackUrl ?? await getRequestURLWN(nuxt), { external })
}

return res
Expand Down Expand Up @@ -89,12 +89,12 @@ const getSession: GetSessionFunc<SessionData | null | void> = async (getSessionO
loading.value = false
lastRefreshedAt.value = new Date()

const { required = false, callbackUrl, onUnauthenticated } = getSessionOptions ?? {}
const { required = false, callbackUrl, onUnauthenticated, external } = getSessionOptions ?? {}
if (required && data.value === null) {
if (onUnauthenticated) {
return onUnauthenticated()
} else {
await navigateTo(callbackUrl ?? await getRequestURLWN(nuxt), { external: true })
await navigateTo(callbackUrl ?? await getRequestURLWN(nuxt), { external })
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,23 @@ export interface SecondarySignInOptions extends Record<string, unknown> {
* @default true
*/
redirect?: boolean
/** Is this callback URL an external one. Setting this to true, allows you to redirect to external urls, however a hard refresh will be done.
*
* @default false
*/
external?: boolean
}

export interface SignOutOptions {
callbackUrl?: string
redirect?: boolean
external?: boolean
}

export type GetSessionOptions = Partial<{
required?: boolean
callbackUrl?: string
external?: boolean,
onUnauthenticated?: () => void
/** Whether to refetch the session even if the token returned by useAuthState is null.
*
Expand Down

0 comments on commit f4295d4

Please sign in to comment.