Skip to content

Commit

Permalink
fix(#967): allow signUp endpoint to be disabled (#968)
Browse files Browse the repository at this point in the history
Co-authored-by: Zoey <[email protected]>
  • Loading branch information
root5427 and zoey-kaiser authored Dec 24, 2024
1 parent 8d31537 commit 52d4b9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { jsonPointerGet, objectFromJsonPointer, useTypedBackendConfig } from '..
import { _fetch } from '../../utils/fetch'
import { determineCallbackUrl } from '../../utils/url'
import { getRequestURLWN } from '../common/getRequestURL'
import { ERROR_PREFIX } from '../../utils/logger'
import { formatToken } from './utils/token'
import { type UseAuthStateReturn, useAuthState } from './useAuthState'
import { callWithNuxt } from '#app/nuxt'
Expand Down Expand Up @@ -163,8 +164,17 @@ async function getSession(getSessionOptions?: GetSessionOptions): Promise<Sessio

async function signUp(credentials: Credentials, signInOptions?: SecondarySignInOptions, signUpOptions?: SignUpOptions) {
const nuxt = useNuxtApp()
const runtimeConfig = useRuntimeConfig()
const config = useTypedBackendConfig(runtimeConfig, 'local')

const signUpEndpoint = config.endpoints.signUp

if (!signUpEndpoint) {
console.warn(`${ERROR_PREFIX} provider.endpoints.signUp is disabled.`)
return
}

const { path, method } = useTypedBackendConfig(useRuntimeConfig(), 'local').endpoints.signUp
const { path, method } = signUpEndpoint
await _fetch(nuxt, path, {
method,
body: credentials
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ export interface ProviderLocal {
*/
signOut?: { path?: string, method?: RouterMethod } | false
/**
* What method and path to call to perform the sign-up.
* What method and path to call to perform the sign-up. Set to false to disable.
*
* @default { path: '/register', method: 'post' }
*/
signUp?: { path?: string, method?: RouterMethod }
signUp?: { path?: string, method?: RouterMethod } | false
/**
* What method and path to call to fetch user / session data from. `nuxt-auth` will send the token received upon sign-in as a header along this request to authenticate.
*
Expand Down

0 comments on commit 52d4b9a

Please sign in to comment.