-
-
Notifications
You must be signed in to change notification settings - Fork 188
Enh(#843): Allow signup flow return data when preventLoginFlow is true #903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
phoenix-ru
merged 21 commits into
sidebase:main
from
iamKiNG-Fr:enh/843-signup-flow-enhancement
Apr 10, 2025
Merged
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e0136bd
added enhancment to allow signUp function return response if SignUpOpβ¦
iamKiNG-Fr 7a4ed34
Merge branch 'main' into enh/843-signup-flow-enhancement
iamKiNG-Fr e3bf0fc
sign up function to return data, test written
iamKiNG-Fr 1bdf144
Discard changes to pnpm-lock.yaml
zoey-kaiser d9951f6
fix: oxlint issue
zoey-kaiser 5477cde
Merge branch 'main' into enh/843-signup-flow-enhancement
iamKiNG-Fr 0caeefc
enh: added generic type support to signUp function for flexible returβ¦
iamKiNG-Fr a76b601
Merge branch 'enh/843-signup-flow-enhancement' of https://github.com/β¦
iamKiNG-Fr 9cff966
Resolved lint errors and formatting issues
iamKiNG-Fr e5373a4
Merge branch 'main' into enh/843-signup-flow-enhancement
zoey-kaiser 6ee85a0
Merge branch 'main' into enh/843-signup-flow-enhancement
iamKiNG-Fr b25597b
Update src/runtime/composables/local/useAuth.ts
iamKiNG-Fr 86fd25a
Update playground-local/pages/register.vue by aligning test-ids
iamKiNG-Fr 94cd4a3
Update playground-local/pages/register.vue to remove unused test-id rβ¦
iamKiNG-Fr f11f9c4
Update playground-local/tests/local.spec.ts by unifying updated test-ids
iamKiNG-Fr 98e33a9
Update src/runtime/composables/local/useAuth.ts
iamKiNG-Fr 75ed74a
Merge branch 'main' into enh/843-signup-flow-enhancement
phoenix-ru 8fd0e24
fix: fix a type in `signUp` function
phoenix-ru f9ac88f
refact: make demo implementation more unified
phoenix-ru 916956f
test: fix E2E tests
phoenix-ru 653f80c
chore: remove unused imports
phoenix-ru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <script setup> | ||
| import { ref } from 'vue' | ||
| import { definePageMeta, useAuth } from '#imports' | ||
| const { signUp } = useAuth() | ||
| const username = ref('') | ||
| const password = ref('') | ||
| const response = ref() | ||
| async function register() { | ||
| try { | ||
| const signUpResponse = await signUp({ username: username.value, password: password.value }, undefined, { preventLoginFlow: true }) | ||
| response.value = signUpResponse | ||
| } | ||
| catch (error) { | ||
| response.value = { error: 'Failed to sign up' } | ||
| console.error(error) | ||
| } | ||
| } | ||
| definePageMeta({ | ||
| auth: { | ||
| unauthenticatedOnly: true, | ||
| navigateAuthenticatedTo: '/', | ||
| }, | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <div> | ||
| <form @submit.prevent="register"> | ||
| <p><i>*password should have at least 6 characters</i></p> | ||
| <input v-model="username" type="text" placeholder="Username" data-testid="regUsername"> | ||
| <input v-model="password" type="password" placeholder="Password" data-testid="regPassword"> | ||
| <button type="submit" data-testid="regSubmit"> | ||
| sign up | ||
| </button> | ||
| </form> | ||
| <div v-if="response"> | ||
| <h2>Response</h2> | ||
| <pre data-testid="regResponse">{{ response }}</pre> | ||
iamKiNG-Fr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </div> | ||
| </div> | ||
| </template> | ||
phoenix-ru marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { createError, eventHandler, readBody } from 'h3' | ||
| import { z } from 'zod' | ||
| import { sign } from 'jsonwebtoken' | ||
|
|
||
| export const SECRET = 'dummy' | ||
|
|
||
| export default eventHandler(async (event) => { | ||
| // Define the schema for validating the incoming data | ||
| const result = z.object({ | ||
| username: z.string(), | ||
| password: z.string().min(6) | ||
| }).safeParse(await readBody(event)) | ||
|
|
||
| // If validation fails, return an error | ||
| if (!result.success) { | ||
| throw createError({ | ||
| statusCode: 400, | ||
| statusMessage: 'Invalid input, please provide a valid email and a password of at least 6 characters.' | ||
| }) | ||
| } | ||
|
|
||
| const { username } = result.data | ||
|
|
||
| const expiresIn = '1h' // token expiry (1 hour) | ||
| const user = { username } // Payload for the token, includes the email | ||
|
|
||
| // Sign the JWT with the user payload and secret | ||
| const accessToken = sign(user, SECRET, { expiresIn }) | ||
|
|
||
| // Return a success response with the email and the token | ||
| return { | ||
| message: 'Signup successful!', | ||
| user: { | ||
| username | ||
| }, | ||
| token: { | ||
| accessToken | ||
| } | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.