Skip to content

Commit

Permalink
refactor(services-bff): Update failed login attempt data retrieval (#…
Browse files Browse the repository at this point in the history
…17213)

* refactor(services-bff): improve login attempt data retrieval

* fix(auth): simplify error handling in login process

Remove unnecessary error code from redirect in the login 
process.
  • Loading branch information
snaerth committed Dec 13, 2024
1 parent a011f03 commit 38cf2da
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions apps/services/bff/src/app/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,24 @@ export class AuthService {
})
}

let loginAttemptData: LoginAttemptData | undefined
const loginAttemptCacheKey = this.cacheService.createSessionKeyType(
'attempt',
query.state,
)
// Get login attempt data from the cache
const loginAttemptData = await this.cacheService.get<LoginAttemptData>(
loginAttemptCacheKey,
// Do not throw an error if the key is not found
false,
)

try {
// Get login attempt from cache
loginAttemptData = await this.cacheService.get<LoginAttemptData>(
this.cacheService.createSessionKeyType('attempt', query.state),
)
if (!loginAttemptData) {
this.logger.warn(this.cacheService.createKeyError(loginAttemptCacheKey))

return this.redirectWithError(res)
}

try {
// Get tokens and user information from the authorization code
const tokenResponse = await this.idsService.getTokens({
code: query.code,
Expand Down

0 comments on commit 38cf2da

Please sign in to comment.