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

Fixed: default OTP for testing and User roles being reset. #93

Merged
merged 7 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,9 @@ export class ApiService {

async loginWithOtp(loginDto: LoginDto, authHeader: null | string): Promise<SignupResponse> {
/* Execution flow
1. Verify OTP
1. Check if ALLOW_DEFAULT_OTP is set to true.
2. If true check if user number is listed in DEFAULT_OTP_USERS, if yes send sucess if OTP matches.
3. else; Verify OTP via fusion auth.
2. If invalid OTP, throw error; else continue with next steps
3. Check if user exists for the given applicationId.
3.1. If existing user, reset the password.
Expand All @@ -544,6 +546,12 @@ export class ApiService {
else
verifyOTPResult = {status: SMSResponseStatus.failure}
}
else {
verifyOTPResult = await this.otpService.verifyOTP({
phone: loginDto.loginId,
otp: loginDto.password, // existing OTP
});
}
} else {
verifyOTPResult = await this.otpService.verifyOTP({
phone: loginDto.loginId,
Expand All @@ -564,11 +572,12 @@ export class ApiService {
authHeader,
);
if (statusFA === FAStatus.USER_EXISTS) {
let registrationId = null;
let registrationId = null, registeredRoles = [];
if (user.registrations) {
user.registrations.map((item) => {
if (item.applicationId == loginDto.applicationId) {
registrationId = item.id;
registeredRoles = item.roles;
}
});
}
Expand All @@ -581,7 +590,7 @@ export class ApiService {
registrations: [
{
applicationId: loginDto.applicationId,
roles: loginDto.roles ?? [],
roles: registeredRoles,
id: registrationId,
},
],
Expand Down
1 change: 0 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ async function bootstrap() {
SwaggerModule.setup('swagger', app, document);
// add security headers
app.use(helmet());

// enable cors
app.enableCors({
origin: process.env.CORS_ALLOWED_ORIGINS?.split(/\s*,\s*/) ?? '*',
Expand Down
Loading