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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot augment user in UserSession #31

Closed
kingyue737 opened this issue Dec 21, 2023 · 2 comments 路 Fixed by #54
Closed

Cannot augment user in UserSession #31

kingyue737 opened this issue Dec 21, 2023 · 2 comments 路 Fixed by #54

Comments

@kingyue737
Copy link
Contributor

kingyue737 commented Dec 21, 2023

The playground project tries to augment UserSession:

But user is already declared here:

馃I don't think it is possible to augment an already declared field of an interface.

Type errors in playground:
image

@Gerbuuun
Copy link
Contributor

Gerbuuun commented Jan 10, 2024

I am getting this TypeError in my project as well. I've been ignoring them for a while now as I haven't found a solution to this yet sadly...

It seems as if the UserSession type is 'stuck'.
Even the requireUserSession function return-type is not what I expect.

export async function requireUserSession(event: H3Event) {
  const userSession = await getUserSession(event)

  if (!userSession.user) {
    throw createError({
      statusCode: 401,
      message: 'Unauthorized'
    })
  }

  return userSession
}

It throws an error when user is falsy (this includes undefined). So when it does return it should be defined right?
Nope... the type is still user: {} | undefined

(edit) I read microsoft/TypeScript#56528 idk if it is the same issue but it is planned for 5.4.0

@kingyue737
Copy link
Contributor Author

I manually remove the user?: {} from node_modules/nuxt-auth-utils/dist/runtime/types/session.d.ts via pnpm patch

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 a pull request may close this issue.

2 participants