Skip to content

Commit 80134e1

Browse files
committed
refactor: update authservice and remove all client references from the password reset files
1 parent 6dfb884 commit 80134e1

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/config/passport.config.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Strategy as FacebookStrategy } from 'passport-facebook';
66
import bcrypt from 'bcryptjs';
77
import { decode as jwtDecode } from 'jsonwebtoken';
88
import User from '../models/user.model';
9-
import Client from '../models/client.model';
109
import 'dotenv/config';
1110

1211
const MAX_FAILED = parseInt(process.env.MAX_FAILED_LOGIN_ATTEMPTS || '', 10) || 3;
@@ -90,9 +89,9 @@ passport.use(
9089
const email = decoded.preferred_username;
9190
const name = decoded.name;
9291

93-
let client = await Client.findOne({ $or: [{ microsoftId }, { email }] });
92+
let client = await User.findOne({ $or: [{ microsoftId }, { email }] });
9493
if (!client) {
95-
client = new Client({ email, name, microsoftId, roles: [] });
94+
client = new User({ email, name, microsoftId, roles: [] });
9695
await client.save();
9796
} else if (!client.microsoftId) {
9897
client.microsoftId = microsoftId;
@@ -158,9 +157,9 @@ if (process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET && process.
158157
const email = profile.emails && profile.emails[0]?.value;
159158
if (!email) return done(null, false);
160159

161-
let client = await Client.findOne({ email });
160+
let client = await User.findOne({ email });
162161
if (!client) {
163-
client = new Client({
162+
client = new User({
164163
email,
165164
name: profile.displayName,
166165
googleId: profile.id,
@@ -234,9 +233,9 @@ if (process.env.FB_CLIENT_ID && process.env.FB_CLIENT_SECRET && process.env.FB_C
234233
const email = profile.emails && profile.emails[0]?.value;
235234
if (!email) return done(null, false);
236235

237-
let client = await Client.findOne({ email });
236+
let client = await User.findOne({ email });
238237
if (!client) {
239-
client = new Client({
238+
client = new User({
240239
email,
241240
name: profile.displayName,
242241
facebookId: profile.id,
@@ -260,7 +259,7 @@ passport.serializeUser((principal: any, done: any) => done(null, principal.id));
260259
passport.deserializeUser(async (id: string, done: any) => {
261260
try {
262261
let principal = await User.findById(id);
263-
if (!principal) principal = await Client.findById(id);
262+
if (!principal) principal = await User.findById(id);
264263
done(null, principal);
265264
} catch (err) {
266265
done(err);

src/controllers/password-reset.controller.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import { randomBytes } from 'node:crypto';
44
import bcrypt from 'bcryptjs';
55
import nodemailer from 'nodemailer';
66
import User from '../models/user.model';
7-
import Client from '../models/client.model';
87

9-
const ACCOUNT_TYPES = ['user', 'client'] as const;
8+
const ACCOUNT_TYPES = ['user'] as const;
109
type AccountType = (typeof ACCOUNT_TYPES)[number];
1110

1211
const isAccountType = (value: unknown): value is AccountType => ACCOUNT_TYPES.includes(value as AccountType);
1312

14-
const getModel = (type: AccountType) => (type === 'user' ? User : Client);
13+
const getModel = (type: AccountType) => (type === 'user' ? User : User);
1514

1615
@Controller('api/auth')
1716
export class PasswordResetController {

src/services/auth.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Injectable } from '@nestjs/common';
2+
import type { SignOptions } from 'jsonwebtoken';
23
import bcrypt from 'bcryptjs';
3-
import jwt from 'jsonwebtoken';
4+
import * as jwt from 'jsonwebtoken';
45
import { UserRepository } from '@repos/user.repository';
56
import { RegisterDto } from '@dtos/register.dto';
67
import { LoginDto } from '@dtos/login.dto';
78
import { MailService } from '@services/mail.service';
89

9-
type JwtExpiry = string | number;
10+
type JwtExpiry = SignOptions['expiresIn'];
1011

1112
@Injectable()
1213
export class AuthService {

0 commit comments

Comments
 (0)