Skip to content

Commit

Permalink
added enhancment to allow signUp function return response if SignUpOp…
Browse files Browse the repository at this point in the history
…tion?.PreventLoginFlow is true
  • Loading branch information
iamKiNG-Fr committed Aug 24, 2024
1 parent b09b14e commit e0136bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 271 deletions.
268 changes: 1 addition & 267 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readonly, type Ref } from 'vue'
import { callWithNuxt } from '#app/nuxt'
import type { CommonUseAuthReturn, SignOutFunc, SignInFunc, GetSessionFunc, SecondarySignInOptions, SignUpOptions, GetSessionOptions } from '../../types'
import type { CommonUseAuthReturn, SignOutFunc, SignInFunc, GetSessionFunc, SecondarySignInOptions, SignUpOptions, GetSessionOptions, SignUpResponse } from '../../types'
import { jsonPointerGet, objectFromJsonPointer, useTypedBackendConfig } from '../../helpers'
import { _fetch } from '../../utils/fetch'
import { getRequestURLWN } from '../../utils/callWithNuxt'
Expand Down Expand Up @@ -150,17 +150,20 @@ const getSession: GetSessionFunc<SessionData | null | void> = async (getSessionO
return data.value
}

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

const { path, method } = useTypedBackendConfig(useRuntimeConfig(), 'local').endpoints.signUp
await _fetch(nuxt, path, {

// Holds result from fetch to be returned if signUpOptions?.preventLoginFlow is true
const result = await _fetch<SignUpResponse>(nuxt, path, {
method,
body: credentials
})

if (signUpOptions?.preventLoginFlow) {
return
// Returns result
return result
}

return signIn(credentials, signInOptions)
Expand Down
9 changes: 9 additions & 0 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export type SessionDataObject = {
| SessionDataObject;
};

/**
* Type of data returned from sign up functiom if preventLoginFlow is true
*/
export type SignUpResponse = {
id?: string; // Optional id field
token?: string; // Optional token field
[key: string]: any; // Allow additional fields with any type
};

/**
* Available `nuxt-auth` authentication providers.
*/
Expand Down

0 comments on commit e0136bd

Please sign in to comment.