Skip to content

Commit 52d4b9a

Browse files
fix(#967): allow signUp endpoint to be disabled (#968)
Co-authored-by: Zoey <[email protected]>
1 parent 8d31537 commit 52d4b9a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/runtime/composables/local/useAuth.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { jsonPointerGet, objectFromJsonPointer, useTypedBackendConfig } from '..
55
import { _fetch } from '../../utils/fetch'
66
import { determineCallbackUrl } from '../../utils/url'
77
import { getRequestURLWN } from '../common/getRequestURL'
8+
import { ERROR_PREFIX } from '../../utils/logger'
89
import { formatToken } from './utils/token'
910
import { type UseAuthStateReturn, useAuthState } from './useAuthState'
1011
import { callWithNuxt } from '#app/nuxt'
@@ -163,8 +164,17 @@ async function getSession(getSessionOptions?: GetSessionOptions): Promise<Sessio
163164

164165
async function signUp(credentials: Credentials, signInOptions?: SecondarySignInOptions, signUpOptions?: SignUpOptions) {
165166
const nuxt = useNuxtApp()
167+
const runtimeConfig = useRuntimeConfig()
168+
const config = useTypedBackendConfig(runtimeConfig, 'local')
169+
170+
const signUpEndpoint = config.endpoints.signUp
171+
172+
if (!signUpEndpoint) {
173+
console.warn(`${ERROR_PREFIX} provider.endpoints.signUp is disabled.`)
174+
return
175+
}
166176

167-
const { path, method } = useTypedBackendConfig(useRuntimeConfig(), 'local').endpoints.signUp
177+
const { path, method } = signUpEndpoint
168178
await _fetch(nuxt, path, {
169179
method,
170180
body: credentials

src/runtime/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ export interface ProviderLocal {
8686
*/
8787
signOut?: { path?: string, method?: RouterMethod } | false
8888
/**
89-
* What method and path to call to perform the sign-up.
89+
* What method and path to call to perform the sign-up. Set to false to disable.
9090
*
9191
* @default { path: '/register', method: 'post' }
9292
*/
93-
signUp?: { path?: string, method?: RouterMethod }
93+
signUp?: { path?: string, method?: RouterMethod } | false
9494
/**
9595
* 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.
9696
*

0 commit comments

Comments
 (0)