Skip to content

Commit

Permalink
N21-1324 school in migration err
Browse files Browse the repository at this point in the history
  • Loading branch information
mrikallab committed Sep 29, 2023
1 parent f503620 commit f82ea23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 11 additions & 1 deletion apps/server/src/modules/oauth/controller/oauth-sso.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { OauthUc } from '../uc';
import { OauthLoginStateDto } from '../uc/dto/oauth-login-state.dto';
import { AuthorizationParams, SSOLoginQuery, SystemIdParams } from './dto';
import { StatelessAuthorizationParams } from './dto/stateless-authorization.params';
import { SchoolInMigrationError } from '../../authentication/errors/school-in-migration.error';

@ApiTags('SSO')
@Controller('sso')
Expand All @@ -47,7 +48,16 @@ export class OauthSSOController {

private errorHandler(error: unknown, session: ISession, res: Response, provider?: string) {
this.logger.error(error);
const ssoError: OAuthSSOError = error instanceof OAuthSSOError ? error : new OAuthSSOError();
// const ssoError: OAuthSSOError = error instanceof OAuthSSOError ? error : new OAuthSSOError();
let ssoError: OAuthSSOError;

if (error instanceof SchoolInMigrationError) {
ssoError = new OAuthSSOError(error.message, error.type);
} else if (error instanceof OAuthSSOError) {
ssoError = error;
} else {
ssoError = new OAuthSSOError();
}

session.destroy((err) => {
this.logger.log(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ export class MigrationCheckService {
);

const user: UserDO | null = await this.userService.findByExternalId(externalUserId, systemId);

if (user?.lastLoginSystemChange && userLoginMigration && !userLoginMigration.closedAt) {
if (!user) {
throw new SchoolInMigrationError();
} else if (user && user.lastLoginSystemChange && userLoginMigration && !userLoginMigration.closedAt) {
const hasMigrated: boolean = user.lastLoginSystemChange > userLoginMigration.startedAt;
return !hasMigrated;
} else {
return !!userLoginMigration && !userLoginMigration.closedAt;
}
/* if (user?.lastLoginSystemChange && userLoginMigration && !userLoginMigration.closedAt) {
const hasMigrated: boolean = user.lastLoginSystemChange > userLoginMigration.startedAt;
return !hasMigrated;
}
Expand Down

0 comments on commit f82ea23

Please sign in to comment.