Skip to content
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

Enh(#843): Allow signup flow return data when preventLoginFlow is true #903

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

iamKiNG-Fr
Copy link

πŸ”— Linked issue

#843

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Added functionality to allow user receive response from server after signup, when preventLoginFlow is true.

image

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.

Copy link

pkg-pr-new bot commented Sep 12, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@sidebase/nuxt-auth@903

commit: 98e33a9

src/runtime/types.ts Outdated Show resolved Hide resolved
playground-local/pages/register.vue Outdated Show resolved Hide resolved
playground-local/pages/register.vue Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update your handler to be closer to a demo implementation introduced in #901?

https://github.com/sidebase/nuxt-auth/blob/main/playground-local/server/api/auth/login.post.ts

I think you either can:

  1. return a "user" object and no access token (we are doing preventLoginFlow, right?) in
    const user = {
    username,
    picture: 'https://github.com/nuxt.png',
    name: `User ${username}`
    }
    ;
  2. or do both "user" object and access tokens as in signIn handler so that reference is usable by others as inspiration and also by tests.
    const tokenData: JwtPayload = { ...user, scope: ['test', 'user'] }
    const accessToken = sign(tokenData, SECRET, {
    expiresIn: ACCESS_TOKEN_TTL
    })
    const refreshToken = sign(tokenData, SECRET, {
    // 1 day
    expiresIn: 60 * 60 * 24
    })
    // Naive implementation - please implement properly yourself!
    const userTokens: TokensByUser = tokensByUser.get(username) ?? {
    access: new Map(),
    refresh: new Map()
    }
    userTokens.access.set(accessToken, refreshToken)
    userTokens.refresh.set(refreshToken, accessToken)
    tokensByUser.set(username, userTokens)
    return {
    token: {
    accessToken,
    refreshToken
    }
    }

It is fine for me if you don't want to implement option 2, I can take it over.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should take over to implement option 2.

I'm not so confident in working with tokens, i would like to learn by seeing your implementation.
I don't mind trying to implement it though if you don't mind, although it might take some trial and error on on my part.

playground-local/tests/local.spec.ts Outdated Show resolved Hide resolved
src/runtime/composables/local/useAuth.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants