diff --git a/docs/content/v0.6/3.application-side/2.session-access-and-management.md b/docs/content/v0.6/3.application-side/2.session-access-and-management.md index 18bbe2b1..be2b6438 100644 --- a/docs/content/v0.6/3.application-side/2.session-access-and-management.md +++ b/docs/content/v0.6/3.application-side/2.session-access-and-management.md @@ -85,6 +85,9 @@ await signIn(credentials) // Trigger a sign-in with a redirect afterwards await signIn(credentials, { callbackUrl: '/protected' }) +// Trigger a sign-in with a redirect afterwards to an external page (if set, this will cause a hard refresh of the page) +await signIn(credentials, { callbackUrl: 'https://sidebase.io', external: true }) + // Trigger a sign-out await signOut() diff --git a/src/runtime/composables/local/useAuth.ts b/src/runtime/composables/local/useAuth.ts index bf4b67d7..ecf49286 100644 --- a/src/runtime/composables/local/useAuth.ts +++ b/src/runtime/composables/local/useAuth.ts @@ -36,10 +36,10 @@ const signIn: SignInFunc = 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 }) } } @@ -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 @@ -89,12 +89,12 @@ const getSession: GetSessionFunc = 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 }) } } diff --git a/src/runtime/types.ts b/src/runtime/types.ts index 77e7b036..3563f6de 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -330,16 +330,23 @@ export interface SecondarySignInOptions extends Record { * @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. *