Skip to content

Commit

Permalink
feat: local provider prevent signIn flow (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
vettndr authored Jan 8, 2024
1 parent 4f7433d commit cac3ce2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readonly, Ref } from 'vue'
import { callWithNuxt } from '#app/nuxt'
import { CommonUseAuthReturn, SignOutFunc, SignInFunc, GetSessionFunc, SecondarySignInOptions } from '../../types'
import { CommonUseAuthReturn, SignOutFunc, SignInFunc, GetSessionFunc, SecondarySignInOptions, SignUpOptions } from '../../types'
import { _fetch } from '../../utils/fetch'
import { jsonPointerGet, useTypedBackendConfig } from '../../helpers'
import { getRequestURLWN } from '../../utils/callWithNuxt'
Expand Down Expand Up @@ -105,7 +105,7 @@ const getSession: GetSessionFunc<SessionData | null | void> = async (getSessionO
return data.value
}

const signUp = async (credentials: Credentials, signInOptions?: SecondarySignInOptions) => {
const signUp = async (credentials: Credentials, signInOptions?: SecondarySignInOptions, signUpOptions?: SignUpOptions) => {
const nuxt = useNuxtApp()

const { path, method } = useTypedBackendConfig(useRuntimeConfig(), 'local').endpoints.signUp
Expand All @@ -114,6 +114,10 @@ const signUp = async (credentials: Credentials, signInOptions?: SecondarySignInO
body: credentials
})

if (signUpOptions?.preventLoginFlow) {
return
}

return signIn(credentials, signInOptions)
}

Expand Down
8 changes: 8 additions & 0 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,14 @@ export interface SecondarySignInOptions extends Record<string, unknown> {
external?: boolean;
}

export interface SignUpOptions extends SecondarySignInOptions {
/** Prevent the signIn flow during registration
*
* @default false
*/
preventLoginFlow?: boolean;
}

export interface SignOutOptions {
callbackUrl?: string;
redirect?: boolean;
Expand Down

0 comments on commit cac3ce2

Please sign in to comment.