Skip to content

Commit b5af548

Browse files
feat: add flag to disable getSession after signIn on local provider (#702)
* feat: ✨ add flag to disable getSession after signIn on local provider * feat: ✨ add flag to disable getSession after signIn on refresh provider * docs: ✨ add flag to disable getSession after signIn on local/refresh provider * fix: 🐛 sync refresh provider redirect external with local provider * refactor: ♻️ rename withGetSession boolean to withSession * docs: 📝 add example to disable getSession with signIn local provider * feat: 🏷️ add withSession flag to SecondarySignInOptions interface * revert: style: 🎨 remove markdownlint md034 url change * docs: 📝 improve type documentation Co-authored-by: Marsel Shaikhin <[email protected]> * refactor: ♻️ rename withSession to callGetSession --------- Co-authored-by: Marsel Shaikhin <[email protected]>
1 parent 0d9ae7a commit b5af548

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

docs/guide/application-side/session-access.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ await signIn(credentials, { callbackUrl: '/protected' })
210210

211211
// Trigger a signIn with a redirect to an external page afterwards
212212
await signIn(credentials, { callbackUrl: 'https://nuxt.org', external: true })
213+
214+
// Trigger a signIn without calling getSession directly. You have to manually call it to get session data.
215+
await signIn(credentials, { callGetSession: false })
213216
```
214217

215218
:::
@@ -321,6 +324,7 @@ setToken('new token')
321324
// Helper method to quickly delete the token cookie (alias for rawToken.value = null)
322325
clearToken()
323326
```
327+
324328
:::
325329

326330
:::warning Local provider:

src/runtime/composables/local/useAuth.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ const signIn: SignInFunc<Credentials, any> = async (credentials, signInOptions,
5555
rawRefreshToken.value = extractedRefreshToken
5656
}
5757

58-
await nextTick(getSession)
58+
const { redirect = true, external, callGetSession = true } = signInOptions ?? {}
59+
60+
if (callGetSession) {
61+
await nextTick(getSession)
62+
}
5963

60-
const { redirect = true, external } = signInOptions ?? {}
6164
let { callbackUrl } = signInOptions ?? {}
6265
if (typeof callbackUrl === 'undefined') {
6366
const redirectQueryParam = useRoute()?.query?.redirect

src/runtime/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,12 @@ export interface SecondarySignInOptions extends Record<string, unknown> {
574574
* @default false
575575
*/
576576
external?: boolean
577+
/**
578+
* Whether `getSession` needs to be called after a successful sign-in. When set to false, you can manually call `getSession` to obtain the session data.
579+
*
580+
* @default true
581+
*/
582+
callGetSession?: boolean
577583
}
578584

579585
export interface SignUpOptions extends SecondarySignInOptions {

0 commit comments

Comments
 (0)