Merged in feat/SW-3461-setup-auth-with-sas-eurobonus (pull request #2825)
Feat/SW-3461 setup auth with sas eurobonus * feat(SW-3461): Setup auth for sas eurobonus * . * feat: setup auth towards SAS * Fix auth via SAS and add logout route * . * merge * auth via SAS * fix powered by scandic logo * Merge branch 'master' of bitbucket.org:scandic-swap/web into feat/SW-3461-setup-auth-with-sas-eurobonus * Include access_token in jwt after successful login * merge Approved-by: Anton Gunnarsson
This commit is contained in:
32
apps/partner-sas/hooks/useIsUserLoggedIn.ts
Normal file
32
apps/partner-sas/hooks/useIsUserLoggedIn.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { useSession } from "next-auth/react"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import type { Session } from "next-auth"
|
||||
|
||||
export function useIsUserLoggedIn() {
|
||||
const { data: session } = useSession()
|
||||
const isUserLoggedIn = isValidClientSession(session)
|
||||
return isUserLoggedIn
|
||||
}
|
||||
|
||||
function isValidClientSession(session: Session | null) {
|
||||
if (!session) {
|
||||
return false
|
||||
}
|
||||
if (session.error) {
|
||||
logger.error(`Session error: ${session.error}`)
|
||||
return false
|
||||
}
|
||||
|
||||
if (session.token.error) {
|
||||
logger.error(`Session token error: ${session.token.error}`)
|
||||
return false
|
||||
}
|
||||
if (session.token.expires_at && session.token.expires_at < Date.now()) {
|
||||
logger.error(`Session expired: ${session.token.expires_at}`)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user