feat: SW-162 Updated as per review comments
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user