feat: SW-162 Updated as per review comments

This commit is contained in:
Hrishikesh Vaipurkar
2024-07-17 16:12:18 +02:00
parent 77feefb1dd
commit 8ab77a5522
5 changed files with 59 additions and 38 deletions

View File

@@ -55,7 +55,7 @@ export const middleware = auth(async (request) => {
nextUrlClone.host = publicUrl.host
nextUrlClone.hostname = publicUrl.hostname
const isMFAValid = async function () {
async function isMFAInvalid() {
const cookieStore = cookies()
const mfaCookieValue = cookieStore.get("_SecureMFA-token")?.value
if (mfaCookieValue) {
@@ -66,22 +66,22 @@ export const middleware = auth(async (request) => {
salt: "_SecureMFA-token",
})
if (mfaToken?.exp) {
return true
return false
}
} catch (e) {
console.log("JWT decode failed", e)
cookieStore.set("_SecureMFA-token", "", { maxAge: 0 })
return false
return true
}
} else {
return false
return true
}
}
if (isLoggedIn && !hasError) {
const isMFAPath = mfaRequired.includes(nextUrl.pathname)
const mfaValid = isMFAPath ? await isMFAValid() : true
if (!mfaValid) {
const mfaInvalid = isMFAPath ? await isMFAInvalid() : false
if (mfaInvalid) {
const mfaLoginUrl = mfaLogin[lang]
const nextUrlClone = nextUrl.clone()
nextUrlClone.host = publicUrl.host