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

fix(ts): adjust properties on default interfaces #1794

Merged
merged 4 commits into from
Apr 21, 2021

Conversation

balazsorban44
Copy link
Member

@balazsorban44 balazsorban44 commented Apr 21, 2021

What:

Adjusting the JWT and Session interfaces

Why:

Here is the shape of the default JWT payload:

const defaultJwtPayload = {
name: user.name,
email: user.email,
picture: user.image,
sub: user.id?.toString()
}

Here is the default Session payload:

const defaultSessionPayload = {
user: {
name: decodedJwt.name || null,
email: decodedJwt.email || null,
image: decodedJwt.picture || null
},
expires: sessionExpires
}

We should make it possible for users to make their own assumptions about the default properties. Currently, because of how type augmentation works, even if you made for example the user field required, it would have been shown as optional, because our default said it was optional. By extracting the default session and JWT interfaces, the user will have full control of those interfaces

How:

Checklist:

  • Documentation
  • Tests
  • Ready to be merged

Thanks to @kripod for the heads-up!

@vercel
Copy link

vercel bot commented Apr 21, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nextauthjs/next-auth/6HXZGQSouiGdgdigDUXZrW8JudAG
✅ Preview: https://next-auth-git-feat-match-default-payloads-nextauthjs.vercel.app

@github-actions github-actions bot added the TypeScript Issues relating to TypeScript label Apr 21, 2021
@vercel vercel bot temporarily deployed to Preview April 21, 2021 09:42 Inactive
@vercel vercel bot temporarily deployed to Preview April 21, 2021 11:20 Inactive
@vercel vercel bot temporarily deployed to Preview April 21, 2021 11:29 Inactive
@balazsorban44 balazsorban44 merged commit eed0001 into main Apr 21, 2021
@balazsorban44 balazsorban44 deleted the feat/match-default-payloads branch April 21, 2021 15:17
@github-actions
Copy link

🎉 This PR is included in version 3.15.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

accessToken?: string
expires: string
}
export interface Session extends Record<string, unknown>, DefaultSession {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the Session and JWT interfaces shouldn’t extend Default{Session,JWT} as that nullifies the point of this change, unfortunately.

Copy link
Member Author

Choose a reason for hiding this comment

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

image
So here is how it looks like for me, when I override Session (in the middle)

Copy link
Contributor

Choose a reason for hiding this comment

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

That worked like charm, thank you! 🙌

@github-actions
Copy link

🎉 This PR is included in version 4.0.0-next.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TypeScript Issues relating to TypeScript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants