Merged in fix/SW-3578-user-is-forced-to-login- (pull request #3044)
fix(SW-3578): Fixed session issue when sas session expires * fix(SW-3578): Fixed session issue when sas session expires * base socialLogin auto-features on validSession and being linked * remove unused object * remove 'import server-only' for isValidSession() since it's only using passed data * remove isValidClientSession() Approved-by: Joakim Jäderberg Approved-by: Anton Gunnarsson
This commit is contained in:
committed by
Joakim Jäderberg
parent
15a2da333d
commit
1c7f72e95d
@@ -9,9 +9,9 @@ import { Avatar } from "@scandic-hotels/design-system/Avatar"
|
||||
import { LoginButton } from "@scandic-hotels/design-system/LoginButton"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
import { trpc } from "@scandic-hotels/trpc/client"
|
||||
import { isValidSession } from "@scandic-hotels/trpc/utils/session"
|
||||
|
||||
import useLang from "@/hooks/useLang"
|
||||
import { isValidClientSession } from "@/utils/clientSession"
|
||||
import { trackLoginClick } from "@/utils/tracking"
|
||||
|
||||
import MyPagesMenu, { MyPagesMenuSkeleton } from "../MyPagesMenu"
|
||||
@@ -27,7 +27,7 @@ export default function MyPagesMenuWrapper() {
|
||||
const loginPathname = useLazyPathname({ includeSearchParams: true })
|
||||
|
||||
const { data: session } = useSession()
|
||||
const isUserLoggedIn = isValidClientSession(session)
|
||||
const isUserLoggedIn = isValidSession(session)
|
||||
|
||||
const { data: user, isLoading: isLoadingUser } = trpc.user.name.useQuery()
|
||||
const { data: membership, isLoading: isLoadingMembership } =
|
||||
|
||||
@@ -5,15 +5,15 @@ import { useSession } from "next-auth/react"
|
||||
|
||||
import { logoutSafely } from "@scandic-hotels/common/constants/routes/handleAuth"
|
||||
import { trpc } from "@scandic-hotels/trpc/client"
|
||||
import { isValidSession } from "@scandic-hotels/trpc/utils/session"
|
||||
|
||||
import { userNotFound } from "@/constants/routes/errorPages"
|
||||
|
||||
import useLang from "@/hooks/useLang"
|
||||
import { isValidClientSession } from "@/utils/clientSession"
|
||||
|
||||
export function UserExists() {
|
||||
const { data: session } = useSession()
|
||||
const isUserLoggedIn = isValidClientSession(session)
|
||||
const isUserLoggedIn = isValidSession(session)
|
||||
const lang = useLang()
|
||||
|
||||
const { isLoading: isLoadingUser, error } = trpc.user.get.useQuery(
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useSession } from "next-auth/react"
|
||||
|
||||
import { isValidClientSession } from "@/utils/clientSession"
|
||||
import { isValidSession } from "@scandic-hotels/trpc/utils/session"
|
||||
|
||||
export function useIsUserLoggedIn() {
|
||||
const { data: session } = useSession()
|
||||
const isUserLoggedIn = isValidClientSession(session)
|
||||
const isUserLoggedIn = isValidSession(session)
|
||||
return isUserLoggedIn
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
|
||||
import type { Session } from "next-auth"
|
||||
|
||||
const logger = createLogger("clientSession")
|
||||
export 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