Merged in fix/my-stay-webview-2 (pull request #2191)
fix: webview - mystay - check if we have webviewToken * fix: webview - mystay - check if we have webviewToken * Cleanup Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -5,10 +5,9 @@ import { overview } from "@/constants/routes/myPages"
|
||||
import { isSignupPage } from "@/constants/routes/signup"
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import ContentPage from "@/components/ContentType/StaticPages/ContentPage"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
|
||||
export { generateMetadata } from "@/utils/generateMetadata"
|
||||
|
||||
@@ -22,8 +21,9 @@ export default async function ContentPagePage() {
|
||||
notFound()
|
||||
}
|
||||
|
||||
const session = await auth()
|
||||
if (isValidSession(session)) {
|
||||
const isLoggedIn = await isLoggedInUser()
|
||||
|
||||
if (isLoggedIn) {
|
||||
redirect(overview[lang])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
getSavedPaymentCardsSafely,
|
||||
} from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import AdditionalInfoForm from "@/components/HotelReservation/FindMyBooking/AdditionalInfoForm"
|
||||
import accessBooking, {
|
||||
ACCESS_GRANTED,
|
||||
@@ -34,9 +33,9 @@ import Image from "@/components/Image"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { setLang } from "@/i18n/serverContext"
|
||||
import MyStayProvider from "@/providers/MyStay"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
import * as maskValue from "@/utils/maskValue"
|
||||
import { parseRefId } from "@/utils/refId"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { getCurrentWebUrl } from "@/utils/url"
|
||||
|
||||
import Tracking from "./tracking"
|
||||
@@ -64,8 +63,7 @@ export default async function MyStay({
|
||||
return notFound()
|
||||
}
|
||||
|
||||
const session = await auth()
|
||||
const isLoggedIn = isValidSession(session)
|
||||
const isLoggedIn = await isLoggedInUser()
|
||||
|
||||
const bv = cookies().get("bv")?.value
|
||||
let bookingConfirmation
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
getSavedPaymentCardsSafely,
|
||||
} from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import AdditionalInfoForm from "@/components/HotelReservation/FindMyBooking/AdditionalInfoForm"
|
||||
import accessBooking, {
|
||||
ACCESS_GRANTED,
|
||||
@@ -34,9 +33,9 @@ import Image from "@/components/Image"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { setLang } from "@/i18n/serverContext"
|
||||
import MyStayProvider from "@/providers/MyStay"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
import * as maskValue from "@/utils/maskValue"
|
||||
import { parseRefId } from "@/utils/refId"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { getCurrentWebUrl } from "@/utils/url"
|
||||
|
||||
import Tracking from "./tracking"
|
||||
@@ -65,8 +64,7 @@ export default async function MyStay({
|
||||
return notFound()
|
||||
}
|
||||
|
||||
const session = await auth()
|
||||
const isLoggedIn = isValidSession(session)
|
||||
const isLoggedIn = await isLoggedInUser()
|
||||
|
||||
const bv = cookies().get("bv")?.value
|
||||
let bookingConfirmation
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import SurpriseIcon from "@scandic-hotels/design-system/Icons/SurpriseIcon"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import Image from "@/components/Image"
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
import Link from "@/components/TempDesignSystem/Link"
|
||||
import BiroScript from "@/components/TempDesignSystem/Text/BiroScript"
|
||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
|
||||
import styles from "./joinScandicFriends.module.css"
|
||||
|
||||
@@ -20,8 +19,7 @@ interface JoinScandicFriendsProps {
|
||||
export default async function JoinScandicFriends({
|
||||
content,
|
||||
}: JoinScandicFriendsProps) {
|
||||
const session = await auth()
|
||||
const isLoggedIn = isValidSession(session)
|
||||
const isLoggedIn = await isLoggedInUser()
|
||||
if (isLoggedIn) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { login } from "@/constants/routes/handleAuth"
|
||||
import { signup } from "@/constants/routes/signup"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import Card from "@/components/TempDesignSystem/Card"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
|
||||
import styles from "./authCard.module.css"
|
||||
|
||||
export default async function EmployeeBenefitsAuthCard() {
|
||||
const session = await auth()
|
||||
const intl = await getIntl()
|
||||
|
||||
const lang = getLang()
|
||||
|
||||
if (isValidSession(session)) {
|
||||
const isLoggedIn = await isLoggedInUser()
|
||||
|
||||
if (isLoggedIn) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { getHeader } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
|
||||
import MobileMenu from "../MobileMenu"
|
||||
|
||||
@@ -10,17 +9,15 @@ export default async function MobileMenuWrapper({
|
||||
}: React.PropsWithChildren) {
|
||||
// preloaded
|
||||
const header = await getHeader()
|
||||
const session = await auth()
|
||||
|
||||
if (!header) {
|
||||
return null
|
||||
}
|
||||
|
||||
const isLoggedIn = await isLoggedInUser()
|
||||
|
||||
return (
|
||||
<MobileMenu
|
||||
topLink={header.data.topLink}
|
||||
isLoggedIn={isValidSession(session)}
|
||||
>
|
||||
<MobileMenu topLink={header.data.topLink} isLoggedIn={isLoggedIn}>
|
||||
{children}
|
||||
</MobileMenu>
|
||||
)
|
||||
|
||||
@@ -5,14 +5,13 @@ import {
|
||||
import { env } from "@/env/server"
|
||||
import { getHeader } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import { IconName } from "@/components/Icons/iconName"
|
||||
import LanguageSwitcher from "@/components/LanguageSwitcher"
|
||||
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
import { getCurrentWebUrl } from "@/utils/url"
|
||||
|
||||
import HeaderLink from "../HeaderLink"
|
||||
@@ -25,8 +24,7 @@ export default async function TopMenu() {
|
||||
const intl = await getIntl()
|
||||
// both preloaded
|
||||
const header = await getHeader()
|
||||
const session = await auth()
|
||||
const isLoggedIn = isValidSession(session)
|
||||
const isLoggedIn = await isLoggedInUser()
|
||||
|
||||
if (!header) {
|
||||
return null
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { getSavedPaymentCardsSafely } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
|
||||
import PaymentClient from "./PaymentClient"
|
||||
|
||||
@@ -14,8 +13,7 @@ export default async function Payment({
|
||||
const savedCreditCards = await getSavedPaymentCardsSafely({
|
||||
supportedCards,
|
||||
})
|
||||
const session = await auth()
|
||||
const isUserLoggedIn = isValidSession(session)
|
||||
const isUserLoggedIn = await isLoggedInUser()
|
||||
|
||||
return (
|
||||
<PaymentClient
|
||||
|
||||
@@ -12,11 +12,10 @@ import {
|
||||
getProfileSafely,
|
||||
} from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
import * as maskValue from "@/utils/maskValue"
|
||||
import { parseRefId } from "@/utils/refId"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
|
||||
import AdditionalInfoForm from "../../FindMyBooking/AdditionalInfoForm"
|
||||
import accessBooking, {
|
||||
@@ -41,8 +40,7 @@ export async function Receipt({ refId }: { refId: string }) {
|
||||
return notFound()
|
||||
}
|
||||
|
||||
const session = await auth()
|
||||
const isLoggedIn = isValidSession(session)
|
||||
const isLoggedIn = await isLoggedInUser()
|
||||
|
||||
const bv = cookies().get("bv")?.value
|
||||
let bookingConfirmation
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import { ScandicFriends } from "@/components/Levels"
|
||||
import LoginButton from "@/components/LoginButton"
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
@@ -8,7 +7,7 @@ import Link from "@/components/TempDesignSystem/Link"
|
||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
|
||||
import Contact from "./Contact"
|
||||
import ReadMore from "./ReadMore"
|
||||
@@ -20,9 +19,9 @@ import type { JoinLoyaltyContactProps } from "@/types/components/sidebar/joinLoy
|
||||
export default async function JoinLoyaltyContact({
|
||||
block,
|
||||
}: JoinLoyaltyContactProps) {
|
||||
const [intl, session] = await Promise.all([getIntl(), auth()])
|
||||
const [intl, isLoggedIn] = await Promise.all([getIntl(), isLoggedInUser()])
|
||||
|
||||
if (isValidSession(session)) {
|
||||
if (isLoggedIn) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import { Suspense } from "react"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import MyPagesSidebar from "@/components/MyPages/Sidebar"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||
|
||||
import SidebarNavigationSkeleton from "../MyPages/Sidebar/SidebarNavigationSkeleton"
|
||||
|
||||
export default async function MyPagesNavigation() {
|
||||
const session = await auth()
|
||||
if (!isValidSession(session)) {
|
||||
const isLoggedIn = await isLoggedInUser()
|
||||
if (!isLoggedIn) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
|
||||
16
apps/scandic-web/utils/isLoggedInUser.ts
Normal file
16
apps/scandic-web/utils/isLoggedInUser.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import "server-only"
|
||||
|
||||
import { cookies } from "next/headers"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
|
||||
import { isValidSession } from "./session"
|
||||
|
||||
export async function isLoggedInUser(): Promise<boolean> {
|
||||
const session = await auth()
|
||||
const cookie = cookies()
|
||||
const webviewTokenCookie = cookie.get("webviewToken")
|
||||
|
||||
// We assume we have a valid session if we have a webviewTokenCookie.
|
||||
return isValidSession(session) || !!webviewTokenCookie?.value
|
||||
}
|
||||
Reference in New Issue
Block a user