Skip to content

Commit

Permalink
dependency version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesthl committed Oct 23, 2023
1 parent d8082db commit f238ff8
Show file tree
Hide file tree
Showing 9 changed files with 2,126 additions and 2,724 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The main apps are:

- [ ] Add support for Android devices (Deep Linking, Sign in with Apple, etc.)
- [ ] Add support for Expo Web
- [ ] Support account linking

## Learn more

Expand Down
32 changes: 16 additions & 16 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,40 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^10.2.5",
"@nestjs/common": "^10.2.7",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.2.5",
"@nestjs/core": "^10.2.7",
"@nestjs/jwt": "^10.1.1",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^10.2.5",
"@nestjs/platform-express": "^10.2.7",
"@nestjs/serve-static": "^4.0.0",
"express": "^4.18.2",
"handlebars": "^4.7.8",
"hbs": "^4.2.0",
"reflect-metadata": "^0.1.13",
"resend": "^1.0.0",
"resend": "^1.1.0",
"rxjs": "^7.8.1",
"supertokens-node": "^15.2.0"
"supertokens-node": "^16.3.3"
},
"devDependencies": {
"@nestjs/cli": "^10.1.17",
"@nestjs/cli": "^10.2.0",
"@nestjs/schematics": "^10.0.2",
"@nestjs/testing": "^10.2.5",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.5",
"@types/node": "^20.6.2",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"eslint": "^8.49.0",
"@nestjs/testing": "^10.2.7",
"@types/express": "^4.17.20",
"@types/jest": "^29.5.6",
"@types/node": "^20.8.7",
"@types/supertest": "^2.0.15",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.4",
"ts-loader": "^9.5.0",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.2.2"
Expand Down
39 changes: 20 additions & 19 deletions apps/api/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from 'supertokens-node/recipe/usermetadata';
import { SessionContainer } from 'supertokens-node/recipe/session';
import { JwtService } from '@nestjs/jwt';
import { deleteUser } from 'supertokens-node';
import supertokens, { deleteUser } from 'supertokens-node';
import { EmailService } from '../email/email.service';

@Controller()
Expand All @@ -40,14 +40,14 @@ export class AuthController {
async getSession(@Session() session: SessionContainer) {
const [metaDataResponse, user, roles] = await Promise.all([
getUserMetadata(session.getUserId()),
ThirdPartyEmailPassword.getUserById(session.getUserId()),
supertokens.getUser(session.getUserId()),
UserRoles.getRolesForUser(session.getTenantId(), session.getUserId()),
]);
if (!user) {
throw new UnauthorizedException();
}
return {
metadata: { ...metaDataResponse.metadata, email: user.email },
metadata: { ...metaDataResponse.metadata, email: user.emails[0] },
session: {
thirdParty: user.thirdParty ?? null,
userId: session.getUserId(),
Expand Down Expand Up @@ -98,7 +98,7 @@ export class AuthController {
);
if (response.status === 'OK') {
await ThirdPartyEmailPassword.updateEmailOrPassword({
userId: response.user.id,
recipeUserId: response.user.recipeUserId,
email: response.user.email,
});
}
Expand All @@ -121,7 +121,7 @@ export class AuthController {
const { oldPassword, newPassword } = body;
const userId = session.getUserId();

const userInfo = await ThirdPartyEmailPassword.getUserById(userId);
const userInfo = await supertokens.getUser(userId);

if (userInfo === undefined) {
throw new Error('Should never come here');
Expand All @@ -130,7 +130,7 @@ export class AuthController {
const passwordValidResponse =
await ThirdPartyEmailPassword.emailPasswordSignIn(
session.getTenantId(),
userInfo.email,
userInfo.emails[0],
oldPassword,
);

Expand All @@ -139,7 +139,7 @@ export class AuthController {
}

const response = await ThirdPartyEmailPassword.updateEmailOrPassword({
userId,
recipeUserId: session.getRecipeUserId(),
password: newPassword,
tenantIdForPasswordPolicy: session!.getTenantId(),
});
Expand Down Expand Up @@ -177,8 +177,8 @@ export class AuthController {
};
}

const sessionId = session.getUserId();
const userAccount = await ThirdPartyEmailPassword.getUserById(sessionId!);
const userId = session.getUserId();
const userAccount = await supertokens.getUser(userId!);
if (userAccount.thirdParty !== undefined) {
return {
status: 'GENERAL_ERROR',
Expand All @@ -187,20 +187,20 @@ export class AuthController {
}

const isVerified = await EmailVerification.isEmailVerified(
session.getUserId(),
session.getRecipeUserId(),
email,
);

if (!isVerified) {
const user = await ThirdPartyEmailPassword.getUserById(
session.getUserId(),
);
const user = await supertokens.getUser(session.getUserId());
for (const tenantId of user.tenantIds) {
// Since once user can be shared across many tenants, we need to check if
// the email already exists in any of the tenants.
const usersWithEmail = await ThirdPartyEmailPassword.getUsersByEmail(
const usersWithEmail = await supertokens.listUsersByAccountInfo(
tenantId,
email,
{
email,
},
);
for (const userWithEmail of usersWithEmail) {
if (userWithEmail.id !== session.getUserId()) {
Expand All @@ -215,13 +215,14 @@ export class AuthController {
const response = await EmailVerification.sendEmailVerificationEmail(
session.getTenantId(),
session.getUserId(),
session.getRecipeUserId(),
email,
);
return response;
}

const response = await ThirdPartyEmailPassword.updateEmailOrPassword({
userId: session.getUserId(),
recipeUserId: session.getRecipeUserId(),
email: email,
});

Expand All @@ -242,14 +243,14 @@ export class AuthController {
expiresIn: '15m',
});

const response = await ThirdPartyEmailPassword.getUserById(userId);
const response = await supertokens.getUser(userId);
if (!response) {
throw new BadRequestException();
}
const { email } = response;
const { emails } = response;
const deleteUrl = `${process.env.API_DOMAIN}/auth/delete-account/verify?token=${token}`;
await this.emailService.sendAccountDeletionMail({
email,
email: emails[0],
accountDeletionLink: deleteUrl,
});
return {
Expand Down
15 changes: 10 additions & 5 deletions apps/api/src/auth/supertokens/supertokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,19 @@ export class SupertokensService {
}
const response =
await originalImplementation.thirdPartySignInUpPOST(input);
if (response.status === 'OK' && response.createdNewUser) {
if (
response.status === 'OK' &&
response.createdNewRecipeUser
) {
let updatedUser:
| {
first_name?: string;
last_name?: string;
avatarUrl?: string;
}
| undefined = undefined;
if (response.user.thirdParty.id === 'apple') {
const [thirdParty] = response.user.thirdParty;
if (thirdParty.id === 'apple') {
const user = response.rawUserInfoFromProvider
.fromIdTokenPayload.user as {
email: string;
Expand All @@ -77,7 +81,7 @@ export class SupertokensService {
first_name: user.first_name,
last_name: user.last_name,
};
} else if (response.user.thirdParty.id === 'github') {
} else if (thirdParty.id === 'github') {
const rawUser = response.rawUserInfoFromProvider
.fromUserInfoAPI as {
user: {
Expand All @@ -92,7 +96,7 @@ export class SupertokensService {
: undefined,
last_name: '',
};
} else if (response.user.thirdParty.id === 'google') {
} else if (thirdParty.id === 'google') {
const user = response.rawUserInfoFromProvider
.fromIdTokenPayload as {
email: string;
Expand Down Expand Up @@ -144,7 +148,8 @@ export class SupertokensService {
await EmailVerification.sendEmailVerificationEmail(
input.tenantId,
response.user.id,
response.user.email,
response.session.getRecipeUserId(),
response.user.emails[0],
input.userContext,
);
await UserRoles.createNewRoleOrAddPermissions('user', [
Expand Down
Loading

0 comments on commit f238ff8

Please sign in to comment.