Skip to content

Commit a5fb640

Browse files
rishabhpoddarnkshah2Rishabhjscyodependabot[bot]
authored
feat!: Next breaking change (#266)
* Usercontext change (#246) * Add logic to use Session recipe with JWTs * Change recipeImplementation functions to normal javascript functions * Change recipeImplementation function format * Add config tests * Add binds when calling originalImplementation functions * Change recipeImplementation to be a function that returns recipe interface * Refactor * Add binds to recipe implementation, adds override tests * Add some unit tests * Update logic for Session with JWT implementation * Add new session class for using Session recipe with JWT recipe, and update recipe implementation to use new session class where required * Refactor based on PR review * Make JWT recipe in Session recipe class def optional * Refactor based on PR review * Allow custom key for jwt in access token payload * Update package version * Update CHANGELOG * Export JWT functions from SessionWrapper export * Refactor to use jsonwebtoken * Add iss claim to jwt payload when creating a session * Refactor config * Update package version * Update session class to use arrow functions * Refactor based on PR comments * Add tests for sub and iss claims * Add tests * Add getPropertyNameFromAccessTokenPayload to config to allow users to handle changing jwt property name overtime * Add tests * Update session class * Update session class * Refactor based on PR comments * Refactor based on PR comments * Add code comments * Add tests * Refactor update access token payload logic for session class * Add tests for _jwtPName * Add tests for session class * Refactor code * Update tests * Add querier check to session override tests * Update session class and recipe implementation logic to use a common function * Fix sessionClass code * Refactor function name for adding JWT to access token payload * adds check for negative jwt expiry when updating it * Fix logic for update access token payload when the new payload is undefined, and add tests * Fix logic for update access token payload when the new payload is undefined, and add tests * Add null check for access token payload when creating a session * Add playground sample for Session init with jwt * adds skeleton and types for passwordless * adds passwordless to with-typescript * adds API paths in passwordless constants fil * finishes normalising app * small change * makes text message sending function compulsory * implements validate email ID default function * implements recipe interface * implements API interface implementation * implements API input parsing * adds logic for sending of email / sms * adds validation of email and phoneNumber in createCode API * removes a done todo * adds helper function to manually create magic links * exposes manually usable functions from passwordless recipe * adds preAuthSessionId to magic link as well * fixes a bug with user type * removes USER_INPUT_CODE_ALREADY_USED_ERROR as a possible output from createCode recipe function * uncomments code that are due to bugs in the core * removes console log * small change to recipe interface * resets passwordless recipe between each test * adds resendCode recipe function test * removes .only and adds another small test * more tests * adds test todos * adds phone number validation logic based on regex * Refactor integration test server to allow for configuring session recipe to use JWT conditionally * Fixes for frontend integration server * adds more test todos * small change with recipe interface type * small types change * fixes issue with consumeCodePOST API output * fixes a bug * adds missing API check * renames resendCode to createNewCodeForDevice * changes checking of device info in resend code APi * adds phone number validation and normilising * Adds passwordless tests (#225) * starts consumeCodeAPI tests * fixs * fixs * adds tests * adds expired userInputCode test * adds create codeAPI test * adds createCodeAPI tests with phone * adds magicURL test * email existsAPI test * adds phoneNumberAPI tests * adds resendCodeAPI test * adds remaining resendCodeAPI test * adds missing fields consumeCode API test * adds check to not run passwordless tests if less than required CDI version * fixs test * adds phone contact method config tests * adds contactMethod email tests * adds more tests * adds remaining config tests * adds basic overriding test * adds udpateUser test * adds revokeCode test * adds remaining recipeFunction tests * implements feedback * adds passwordless tests * fixs test * fixs function * removes unnecessary variable * updates fdi version * Add open id recipe and change session recipe to use open id instead of jwt directly (#226) * Add open id recipe * Refactor existing tests * Refactor openid recipe config and add tests * Add api and override tests * Make cors origin header * for getJWKS and open id discovery endpoints * Refactor based on PR comments * Move logic of adding iss claim to open id recipe * Update tests * Update logic for default issuer and add test for init with gateway path * Refactor based on PR comments * Add null check for payload in open id createJWT * adds 1.11 as FDI Co-authored-by: Rishabh <[email protected]> * adds preAuthSessionId as an input to consumeCode and removes it from the output * Passwordless test changes (#228) * fixs some tests * fixs * updates CHANGELOG.md * adds integration tests changes (#229) Co-authored-by: Rishabh <[email protected]> * makes userContext part of the input object * makes changes to all types and to emailpassword recipe * makes changes to emailverification recipe * removes unnecessary type param * removes unnecessary type param * adds context for jwt and openid recipe as well * adds userContext everywhere * fixes a bug * fixes a bug * adds basic userContext test * adds missing context passing * adds missing userContext * adds missing userContext * adds missing userContext * removes userContext from session container interface Co-authored-by: Nemi Shah <[email protected]> Co-authored-by: Rishabh <[email protected]> Co-authored-by: Joel Coutinho <[email protected]> * Bump follow-redirects from 1.14.6 to 1.14.7 in /test/auth-react-server (#245) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.14.6 to 1.14.7. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](follow-redirects/follow-redirects@v1.14.6...v1.14.7) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump follow-redirects from 1.14.4 to 1.14.7 (#243) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.14.4 to 1.14.7. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](follow-redirects/follow-redirects@v1.14.4...v1.14.7) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump next from 11.0.0 to 11.1.3 (#227) Bumps [next](https://github.com/vercel/next.js) from 11.0.0 to 11.1.3. - [Release notes](https://github.com/vercel/next.js/releases) - [Changelog](https://github.com/vercel/next.js/blob/canary/release.js) - [Commits](vercel/next.js@v11.0.0...v11.1.3) --- updated-dependencies: - dependency-name: next dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump validator from 13.6.0 to 13.7.0 (#206) Bumps [validator](https://github.com/validatorjs/validator.js) from 13.6.0 to 13.7.0. - [Release notes](https://github.com/validatorjs/validator.js/releases) - [Changelog](https://github.com/validatorjs/validator.js/blob/master/CHANGELOG.md) - [Commits](validatorjs/validator.js@13.6.0...13.7.0) --- updated-dependencies: - dependency-name: validator dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * adds user context to session class functions (#255) * feat: adds user context to session class functions and adds a new recipe interface function to session recipe Co-authored-by: Rishabh <[email protected]> * adds missing userContext passing * exposes regenerateAccessToken to the user via session/index.ts file * adds user context to social provider definitions too Co-authored-by: Nemi Shah <[email protected]> Co-authored-by: Rishabh <[email protected]> Co-authored-by: Joel Coutinho <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent d9e47f8 commit a5fb640

File tree

134 files changed

+2119
-9846
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+2119
-9846
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
77
.
88

9+
## [9.0.0] - 2022-02-20
10+
11+
### Breaking Change
12+
13+
- Adds user context to all functions exposed to the user, and to API and Recipe interface functions.
14+
- Returns session from API interface functions that create a session
15+
16+
### Change:
17+
18+
- Uses recipe interface inside session class so that any modification to those get reflected in the session class functions too.
19+
920
## [8.6.1] - 2022-02-09
1021

22+
### Refactor
23+
1124
- Removes unused property from session recipe
1225

1326
## [8.6.0] - 2022-01-31
@@ -21,6 +34,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2134

2235
- Adds ability to give a path for each of the hostnames in the connectionURI: https://github.com/supertokens/supertokens-node/issues/252
2336
- add workflow to verify if pr title follows conventional commits
37+
- Added `regenerateAccessToken` as a new recipe function for the session recipe.
38+
39+
### Breaking changes:
40+
41+
- Allows passing of custom user context everywhere: https://github.com/supertokens/supertokens-node/issues/215
42+
- Returns session object from API interface functions which create a new session: https://github.com/supertokens/supertokens-node/issues/215
2443

2544
## [8.5.0] - 2022-01-14
2645

lib/build/recipe/emailpassword/api/emailExists.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function emailExists(apiImplementation, options) {
6060
message: "Please provide the email as a GET param",
6161
});
6262
}
63-
let result = yield apiImplementation.emailExistsGET({ email, options });
63+
let result = yield apiImplementation.emailExistsGET({ email, options, userContext: {} });
6464
utils_1.send200Response(options.res, result);
6565
return true;
6666
});

lib/build/recipe/emailpassword/api/generatePasswordResetToken.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function generatePasswordResetToken(apiImplementation, options) {
5858
options.config.resetPasswordUsingTokenFeature.formFieldsForGenerateTokenForm,
5959
(yield options.req.getJSONBody()).formFields
6060
);
61-
let result = yield apiImplementation.generatePasswordResetTokenPOST({ formFields, options });
61+
let result = yield apiImplementation.generatePasswordResetTokenPOST({ formFields, options, userContext: {} });
6262
utils_1.send200Response(options.res, result);
6363
return true;
6464
});

lib/build/recipe/emailpassword/api/implementation.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,50 @@ Object.defineProperty(exports, "__esModule", { value: true });
3434
const session_1 = require("../../session");
3535
function getAPIImplementation() {
3636
return {
37-
emailExistsGET: function ({ email, options }) {
37+
emailExistsGET: function ({ email, options, userContext }) {
3838
return __awaiter(this, void 0, void 0, function* () {
39-
let user = yield options.recipeImplementation.getUserByEmail({ email });
39+
let user = yield options.recipeImplementation.getUserByEmail({ email, userContext });
4040
return {
4141
status: "OK",
4242
exists: user !== undefined,
4343
};
4444
});
4545
},
46-
generatePasswordResetTokenPOST: function ({ formFields, options }) {
46+
generatePasswordResetTokenPOST: function ({ formFields, options, userContext }) {
4747
return __awaiter(this, void 0, void 0, function* () {
4848
let email = formFields.filter((f) => f.id === "email")[0].value;
49-
let user = yield options.recipeImplementation.getUserByEmail({ email });
49+
let user = yield options.recipeImplementation.getUserByEmail({ email, userContext });
5050
if (user === undefined) {
5151
return {
5252
status: "OK",
5353
};
5454
}
55-
let response = yield options.recipeImplementation.createResetPasswordToken({ userId: user.id });
55+
let response = yield options.recipeImplementation.createResetPasswordToken({
56+
userId: user.id,
57+
userContext,
58+
});
5659
if (response.status === "UNKNOWN_USER_ID_ERROR") {
5760
return {
5861
status: "OK",
5962
};
6063
}
6164
let passwordResetLink =
62-
(yield options.config.resetPasswordUsingTokenFeature.getResetPasswordURL(user)) +
65+
(yield options.config.resetPasswordUsingTokenFeature.getResetPasswordURL(user, userContext)) +
6366
"?token=" +
6467
response.token +
6568
"&rid=" +
6669
options.recipeId;
6770
try {
6871
if (!options.isInServerlessEnv) {
6972
options.config.resetPasswordUsingTokenFeature
70-
.createAndSendCustomEmail(user, passwordResetLink)
73+
.createAndSendCustomEmail(user, passwordResetLink, userContext)
7174
.catch((_) => {});
7275
} else {
7376
// see https://github.com/supertokens/supertokens-node/pull/135
7477
yield options.config.resetPasswordUsingTokenFeature.createAndSendCustomEmail(
7578
user,
76-
passwordResetLink
79+
passwordResetLink,
80+
userContext
7781
);
7882
}
7983
} catch (_) {}
@@ -82,41 +86,47 @@ function getAPIImplementation() {
8286
};
8387
});
8488
},
85-
passwordResetPOST: function ({ formFields, token, options }) {
89+
passwordResetPOST: function ({ formFields, token, options, userContext }) {
8690
return __awaiter(this, void 0, void 0, function* () {
8791
let newPassword = formFields.filter((f) => f.id === "password")[0].value;
88-
let response = yield options.recipeImplementation.resetPasswordUsingToken({ token, newPassword });
92+
let response = yield options.recipeImplementation.resetPasswordUsingToken({
93+
token,
94+
newPassword,
95+
userContext,
96+
});
8997
return response;
9098
});
9199
},
92-
signInPOST: function ({ formFields, options }) {
100+
signInPOST: function ({ formFields, options, userContext }) {
93101
return __awaiter(this, void 0, void 0, function* () {
94102
let email = formFields.filter((f) => f.id === "email")[0].value;
95103
let password = formFields.filter((f) => f.id === "password")[0].value;
96-
let response = yield options.recipeImplementation.signIn({ email, password });
104+
let response = yield options.recipeImplementation.signIn({ email, password, userContext });
97105
if (response.status === "WRONG_CREDENTIALS_ERROR") {
98106
return response;
99107
}
100108
let user = response.user;
101-
yield session_1.default.createNewSession(options.res, user.id, {}, {});
109+
let session = yield session_1.default.createNewSession(options.res, user.id, {}, {}, userContext);
102110
return {
103111
status: "OK",
112+
session,
104113
user,
105114
};
106115
});
107116
},
108-
signUpPOST: function ({ formFields, options }) {
117+
signUpPOST: function ({ formFields, options, userContext }) {
109118
return __awaiter(this, void 0, void 0, function* () {
110119
let email = formFields.filter((f) => f.id === "email")[0].value;
111120
let password = formFields.filter((f) => f.id === "password")[0].value;
112-
let response = yield options.recipeImplementation.signUp({ email, password });
121+
let response = yield options.recipeImplementation.signUp({ email, password, userContext });
113122
if (response.status === "EMAIL_ALREADY_EXISTS_ERROR") {
114123
return response;
115124
}
116125
let user = response.user;
117-
yield session_1.default.createNewSession(options.res, user.id, {}, {});
126+
let session = yield session_1.default.createNewSession(options.res, user.id, {}, {}, userContext);
118127
return {
119128
status: "OK",
129+
session,
120130
user,
121131
};
122132
});

lib/build/recipe/emailpassword/api/passwordReset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function passwordReset(apiImplementation, options) {
7272
message: "The password reset token must be a string",
7373
});
7474
}
75-
let result = yield apiImplementation.passwordResetPOST({ formFields, token, options });
75+
let result = yield apiImplementation.passwordResetPOST({ formFields, token, options, userContext: {} });
7676
utils_1.send200Response(
7777
options.res,
7878
result.status === "OK"

lib/build/recipe/emailpassword/api/signin.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ function signInAPI(apiImplementation, options) {
5858
options.config.signInFeature.formFields,
5959
(yield options.req.getJSONBody()).formFields
6060
);
61-
let result = yield apiImplementation.signInPOST({ formFields, options });
62-
utils_1.send200Response(options.res, result);
61+
let result = yield apiImplementation.signInPOST({ formFields, options, userContext: {} });
62+
if (result.status === "OK") {
63+
utils_1.send200Response(options.res, {
64+
status: "OK",
65+
user: result.user,
66+
});
67+
} else {
68+
utils_1.send200Response(options.res, result);
69+
}
6370
return true;
6471
});
6572
}

lib/build/recipe/emailpassword/api/signup.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ function signUpAPI(apiImplementation, options) {
5959
options.config.signUpFeature.formFields,
6060
(yield options.req.getJSONBody()).formFields
6161
);
62-
let result = yield apiImplementation.signUpPOST({ formFields, options });
62+
let result = yield apiImplementation.signUpPOST({ formFields, options, userContext: {} });
6363
if (result.status === "OK") {
64-
utils_1.send200Response(options.res, result);
64+
utils_1.send200Response(options.res, {
65+
status: "OK",
66+
user: result.user,
67+
});
6568
} else {
6669
throw new error_1.default({
6770
type: error_1.default.FIELD_ERROR,

lib/build/recipe/emailpassword/index.d.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export default class Wrapper {
77
static Error: typeof SuperTokensError;
88
static signUp(
99
email: string,
10-
password: string
10+
password: string,
11+
userContext?: any
1112
): Promise<
1213
| {
1314
status: "OK";
@@ -19,7 +20,8 @@ export default class Wrapper {
1920
>;
2021
static signIn(
2122
email: string,
22-
password: string
23+
password: string,
24+
userContext?: any
2325
): Promise<
2426
| {
2527
status: "OK";
@@ -29,10 +31,11 @@ export default class Wrapper {
2931
status: "WRONG_CREDENTIALS_ERROR";
3032
}
3133
>;
32-
static getUserById(userId: string): Promise<User | undefined>;
33-
static getUserByEmail(email: string): Promise<User | undefined>;
34+
static getUserById(userId: string, userContext?: any): Promise<User | undefined>;
35+
static getUserByEmail(email: string, userContext?: any): Promise<User | undefined>;
3436
static createResetPasswordToken(
35-
userId: string
37+
userId: string,
38+
userContext?: any
3639
): Promise<
3740
| {
3841
status: "OK";
@@ -44,7 +47,8 @@ export default class Wrapper {
4447
>;
4548
static resetPasswordUsingToken(
4649
token: string,
47-
newPassword: string
50+
newPassword: string,
51+
userContext?: any
4852
): Promise<
4953
| {
5054
status: "OK";
@@ -58,11 +62,13 @@ export default class Wrapper {
5862
userId: string;
5963
email?: string;
6064
password?: string;
65+
userContext?: any;
6166
}): Promise<{
6267
status: "OK" | "EMAIL_ALREADY_EXISTS_ERROR" | "UNKNOWN_USER_ID_ERROR";
6368
}>;
6469
static createEmailVerificationToken(
65-
userId: string
70+
userId: string,
71+
userContext?: any
6672
): Promise<
6773
| {
6874
status: "OK";
@@ -73,22 +79,25 @@ export default class Wrapper {
7379
}
7480
>;
7581
static verifyEmailUsingToken(
76-
token: string
82+
token: string,
83+
userContext?: any
7784
): Promise<
7885
| {
7986
status: "EMAIL_VERIFICATION_INVALID_TOKEN_ERROR";
8087
}
8188
| User
8289
| undefined
8390
>;
84-
static isEmailVerified(userId: string): Promise<boolean>;
91+
static isEmailVerified(userId: string, userContext?: any): Promise<boolean>;
8592
static revokeEmailVerificationTokens(
86-
userId: string
93+
userId: string,
94+
userContext?: any
8795
): Promise<{
8896
status: "OK";
8997
}>;
9098
static unverifyEmail(
91-
userId: string
99+
userId: string,
100+
userContext?: any
92101
): Promise<{
93102
status: "OK";
94103
}>;

0 commit comments

Comments
 (0)