-
Notifications
You must be signed in to change notification settings - Fork 84
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
feat!: Account linking #670
Changes from 82 commits
170c677
08c2b89
1c8b4f5
7973b8c
1d98e90
3148dc1
d233bbc
3046204
765d915
35c1e93
8b493a7
b678e7d
211c898
651d2e7
b14e25d
81d0055
559539b
808f75c
89baf8e
9a093cb
de00244
73f3b7c
39c9636
f77d909
2130c6e
a26c48b
683ed8b
777f363
8296c17
b2ba9b2
8c5c992
8d00959
802bb26
17e2002
e791146
b7a58e3
147be98
aa12c03
37ec32e
05719a3
96e9fb4
0522927
24ef7a3
9ceaae6
dd87174
7b4d4d1
82ddf38
a4e186c
c9c9082
a21bf65
a284b04
966e9d9
9ab4f61
5093a2a
59e933a
7a7315b
f0c8bc1
244a225
f3fcaf8
dcf849f
37c66d3
9463064
2a82e65
8cf2eef
8db8133
2a6cb57
0bf3742
d737abd
c57a784
e110712
f723447
67efb36
5da23d8
dc681e3
74ba078
bb74f9b
ff5f182
825888f
4f1a681
1140130
68c4803
340d80f
56255ee
d2b8684
617d882
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,188 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||||
|
||||||
## [unreleased] | ||||||
|
||||||
## [16.0.0] - 2023-08-XX | ||||||
|
||||||
rishabhpoddar marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
### Breaking changes | ||||||
|
||||||
rishabhpoddar marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- Now only supporting CDI 4.0. Compatible with core version >= 7.0 | ||||||
- Now supporting FDI 1.18 | ||||||
- removed the recipe specific `User` type, now all functions are using the new generic `User` type | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also link to this page: supertokens.com/docs/thirdpartyemailpassword/user-object |
||||||
- The `fetchValue` callback of claims now take a new `recipeUserId` param | ||||||
rishabhpoddar marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- Now ignoring protected props in the payload in `createNewSession` and `createNewSessionWithoutRequestResponse` | ||||||
- `createdNewUser` has been renamed to `createdNewRecipeUser` in sign up related APIs and functions | ||||||
|
||||||
- EmailPassword: | ||||||
- removed `getUserById`, `getUserByEmail`. You should use `supertokens.getUser`, and `supertokens. listUsersByAccountInfo` instead | ||||||
- added `consumePasswordResetToken`. This function allows the consumption of the reset password token without changing the password. It will return OK if the token was valid. | ||||||
- added an overrideable `createNewRecipeUser` function that is called during sign up and password reset flow (in case a new email password user is being created on the fly). This is mostly for internal use. | ||||||
- `recipeUserId` is added to the input of `getContent` of the email delivery config | ||||||
- `email` was added to the input of `createResetPasswordToken` , `sendResetPasswordEmail`, `createResetPasswordLink` | ||||||
- `updateEmailOrPassword` : | ||||||
- now takes `recipeUserId` instead of `userId` | ||||||
- can return the new `EMAIL_CHANGE_NOT_ALLOWED_ERROR` status | ||||||
- `signIn`: | ||||||
- returns `recipeUserId` | ||||||
- `signUp`: | ||||||
- returns `recipeUserId` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
- `signInPOST`: | ||||||
- can return status `SIGN_IN_NOT_ALLOWED` | ||||||
- `signUpPOST`: | ||||||
- can return status `SIGN_UP_NOT_ALLOWED` | ||||||
- `generatePasswordResetTokenPOST`: | ||||||
- can now return `PASSWORD_RESET_NOT_ALLOWED` | ||||||
- `passwordResetPOST`: | ||||||
- now returns the `user` and the `email` whose password was reset | ||||||
- can now return `PASSWORD_POLICY_VIOLATED_ERROR` | ||||||
rishabhpoddar marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- EmailVerification: | ||||||
- `createEmailVerificationToken`, `createEmailVerificationLink`, `isEmailVerified`, `revokeEmailVerificationTokens` , `unverifyEmail`: | ||||||
- now takes `recipeUserId` instead of `userId` | ||||||
- `sendEmailVerificationEmail` : | ||||||
- now takes an additional `recipeUserId` parameter | ||||||
- `verifyEmailUsingToken`: | ||||||
- now takes a new `attemptAccountLinking` parameter | ||||||
- returns the `recipeUserId` instead of `id` | ||||||
- `sendEmail` now requires a new `recipeUserId` as part of the user info | ||||||
- `getEmailForUserId` config option was renamed to `getEmailForRecipeUserId` | ||||||
- `verifyEmailPOST`, `generateEmailVerifyTokenPOST`: returns an optional `newSession` in case the current user session needs to be updated | ||||||
- Passwordless: | ||||||
- removed `getUserById`, `getUserByEmail`, `getUserByPhoneNumber` | ||||||
- `updateUser` : | ||||||
- now takes `recipeUserId` instead of `userId` | ||||||
- can return `"EMAIL_CHANGE_NOT_ALLOWED_ERROR` and `PHONE_NUMBER_CHANGE_NOT_ALLOWED_ERROR` statuses | ||||||
- `createCodePOST` and `consumeCodePOST` can now return `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- Session: | ||||||
- access tokens and session objects now contain the recipe user id | ||||||
- Support for new access token version | ||||||
- `recipeUserId` is now added to the payload of the `TOKEN_THEFT_DETECTED` error | ||||||
- `createNewSession`: now takes `recipeUserId` instead of `userId` | ||||||
- Removed `validateClaimsInJWTPayload` | ||||||
- `revokeAllSessionsForUser` now takes an optional `revokeSessionsForLinkedAccounts` param | ||||||
- `getAllSessionHandlesForUser` now takes an optional `fetchSessionsForAllLinkedAccounts` param | ||||||
- `regenerateAccessToken` return value now includes `recipeUserId` | ||||||
- `getGlobalClaimValidators` and `validateClaims` now get a new `recipeUserId` param | ||||||
- Added `getRecipeUserId` to the session class | ||||||
- ThirdParty: | ||||||
- The `signInUp` override: | ||||||
- gets a new `isVerified` param | ||||||
- can return new status: `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- `manuallyCreateOrUpdateUser`: | ||||||
- gets a new `isVerified` param | ||||||
- can return new statuses: `EMAIL_CHANGE_NOT_ALLOWED_ERROR`, `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- Removed `getUserByThirdPartyInfo`, `getUsersByEmail`, `getUserById` | ||||||
- `signInUpPOST` can now return `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- ThirdPartyEmailPassword: | ||||||
- Removed `getUserByThirdPartyInfo`, `getUsersByEmail`, `getUserById` | ||||||
- `thirdPartyManuallyCreateOrUpdateUser`: | ||||||
- now get a new `isVerified` param | ||||||
- can return new statuses: `EMAIL_CHANGE_NOT_ALLOWED_ERROR`, `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- The `thirdPartySignInUp` override: | ||||||
- now get a new `isVerified` param | ||||||
- can return new status: `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- `email` was added to the input of `createResetPasswordToken` , `sendResetPasswordEmail`, `createResetPasswordLink` | ||||||
- added an overrideable `createNewEmailPasswordRecipeUser` function that is called during email password sign up and in the “invitation link” flow | ||||||
- added `consumePasswordResetToken` | ||||||
- `updateEmailOrPassword` : | ||||||
- now takes `recipeUserId` instead of `userId` | ||||||
- can return the new `EMAIL_CHANGE_NOT_ALLOWED_ERROR` status | ||||||
- added an overrideable `createNewEmailPasswordRecipeUser` function that is called during sign up and in the “invitation link” flow | ||||||
- `emailPasswordSignIn`: | ||||||
- returns `recipeUserId` | ||||||
- `emailPasswordSignUp`: | ||||||
- returns `recipeUserId` | ||||||
- `emailPasswordSignInPOST`: | ||||||
- can return status `SIGN_IN_NOT_ALLOWED` | ||||||
- `emailPasswordSignUpPOST`: | ||||||
- can return status `SIGN_UP_NOT_ALLOWED` | ||||||
- `generatePasswordResetTokenPOST`: | ||||||
- can now return `PASSWORD_RESET_NOT_ALLOWED` | ||||||
- `passwordResetPOST`: | ||||||
- now returns the `user` and the `email` whose password was reset | ||||||
- can now return `PASSWORD_POLICY_VIOLATED_ERROR` | ||||||
- `thirdPartySignInUpPOST` can now return `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- ThirdPartyPasswordless: | ||||||
- Removed `getUserByThirdPartyInfo`, `getUsersByEmail`, `getUserByPhoneNumber`, `getUserById` | ||||||
- `thirdPartyManuallyCreateOrUpdateUser`: | ||||||
- gets a new `isVerified` param | ||||||
- can return new statuses: `EMAIL_CHANGE_NOT_ALLOWED_ERROR`, `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- The `thirdPartySignInUp` override: | ||||||
- gets a new `isVerified` param | ||||||
- can return new status: `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- `updatePasswordlessUser`: | ||||||
- now takes `recipeUserId` instead of `userId` | ||||||
- can return `"EMAIL_CHANGE_NOT_ALLOWED_ERROR` and `PHONE_NUMBER_CHANGE_NOT_ALLOWED_ERROR` statuses | ||||||
- `thirdPartySignInUpPOST` can now return `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- `createCodePOST` and `consumeCodePOST` can now return `SIGN_IN_UP_NOT_ALLOWED` | ||||||
- Multitenancy: | ||||||
- `associateUserToTenant` can now return `ASSOCIATION_NOT_ALLOWED_ERROR` | ||||||
- `associateUserToTenant` and `disassociateUserFromTenant` now take `RecipeUserId` instead of a string user id | ||||||
|
||||||
### Changes | ||||||
|
||||||
- Added `RecipeUserId` and a generic `User` class | ||||||
- Added `getUser`, `listUsersByAccountInfo`, `convertToRecipeUserId` to the main exports | ||||||
- Updated compilation target of typescript to ES2017 to make debugging easier. | ||||||
- Added account-linking recipe | ||||||
|
||||||
### Migration guide | ||||||
|
||||||
#### New User structure | ||||||
|
||||||
We've added a generic `User` class instead of the old recipe specific ones. The mapping of old props to new in case you are not using account-linking: | ||||||
|
||||||
- `user.id` stays `user.id` (or `user.loginMethods[0].recipeUserId` in case you need `RecipeUserId`) | ||||||
- `user.email` becomes `user.emails[0]` | ||||||
- `user.phoneNumber` becomes `user.phoneNumbers[0]` | ||||||
- `user.thirdParty` becomes `user.thirdParty[0]` | ||||||
- `user.timeJoined` is still `user.timeJoined` | ||||||
- `user.tenantIds` is still `user.tenantIds` | ||||||
|
||||||
#### RecipeUserId | ||||||
|
||||||
Some functions now require you to pass a `RecipeUserId` instead of a string user id. If you are using our auth recipes, you can find the recipeUserId as: `user.loginMethods[0].recipeUserId` (you'll need to worry about selecting the right login method after enabling account linking). Alternatively, if you already have a string user id you can convert it to a `RecipeUserId` using `supertokens.convertToRecipeUserId(userIdString)` | ||||||
|
||||||
#### Checking if a user signed up or signed in | ||||||
|
||||||
- In the emailpassword sign up / passwordless consumeCode / social login signinup APIs, you can check if a user signed up by: | ||||||
|
||||||
``` | ||||||
// Here res refers to the result the function/api functions mentioned above. | ||||||
const isNewUser = res.createdNewRecipeUser && res.user.loginMethod.length === 1; | ||||||
``` | ||||||
|
||||||
- You can check if a new primary user was created by `EmailPassword.signUp`, `signUpPOST` or `createNewRecipeUser` (and their ThirdParyEmailPassword counterparts) by: | ||||||
|
||||||
``` | ||||||
const isNewPrimaryUser = res.user.loginMethod.length === 1; | ||||||
``` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. huh? Not sure why this is needed. Did you mean that you can check if a new user signed in? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this is different from the above, since EP signup doesn't have |
||||||
|
||||||
#### Changing user emails | ||||||
|
||||||
- We recommend that you check if the email change of a user is allowed, before calling the update function | ||||||
- Check [here](https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/change-email-post-login) for more information | ||||||
|
||||||
``` | ||||||
import {isEmailChangeAllowed} from "supertokens-node/recipe/accountlinking"; | ||||||
/// ... | ||||||
app.post("/change-email", verifySession(), async (req: SessionRequest, res: express.Response) => { | ||||||
let session = req.session!; | ||||||
let email = req.body.email; | ||||||
|
||||||
// ... | ||||||
if (!(await isEmailChangeAllowed(session.getRecipeUserId(), email, false))) { | ||||||
// this can come here if you have enabled the account linking feature, and | ||||||
// if there is a security risk in changing this user's email. | ||||||
} | ||||||
|
||||||
// Update the email | ||||||
let resp = await ThirdPartyEmailPassword.updateEmailOrPassword({ | ||||||
recipeUserId: session.getRecipeUserId(), | ||||||
email: email, | ||||||
}); | ||||||
// ... | ||||||
}); | ||||||
``` | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to have a section on frontend / core migration needed - that these are the versions of the frontend and core. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The supported FE version didn't change if you are not using account linking, and the core is mentioned above. I can add a section/link here pointing to the account linking recipe docs. |
||||||
## [15.2.0] - 2023-09-11 | ||||||
|
||||||
### Added | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"_comment": "contains a list of core-driver interfaces branch names that this core supports", | ||
"versions": ["3.0"] | ||
"versions": ["4.0"] | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add changelog. In that, also mention that the way we check for sign up condition in functions override (like in email password sign up), has changed, and that you should also check for loginMethods length. Show code snippet too