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 { isSignupPage } from "@/constants/routes/signup"
|
||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
|
||||||
import ContentPage from "@/components/ContentType/StaticPages/ContentPage"
|
import ContentPage from "@/components/ContentType/StaticPages/ContentPage"
|
||||||
import { getLang } from "@/i18n/serverContext"
|
import { getLang } from "@/i18n/serverContext"
|
||||||
import { isValidSession } from "@/utils/session"
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
|
|
||||||
export { generateMetadata } from "@/utils/generateMetadata"
|
export { generateMetadata } from "@/utils/generateMetadata"
|
||||||
|
|
||||||
@@ -22,8 +21,9 @@ export default async function ContentPagePage() {
|
|||||||
notFound()
|
notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = await auth()
|
const isLoggedIn = await isLoggedInUser()
|
||||||
if (isValidSession(session)) {
|
|
||||||
|
if (isLoggedIn) {
|
||||||
redirect(overview[lang])
|
redirect(overview[lang])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import {
|
|||||||
getSavedPaymentCardsSafely,
|
getSavedPaymentCardsSafely,
|
||||||
} from "@/lib/trpc/memoizedRequests"
|
} from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
|
||||||
import AdditionalInfoForm from "@/components/HotelReservation/FindMyBooking/AdditionalInfoForm"
|
import AdditionalInfoForm from "@/components/HotelReservation/FindMyBooking/AdditionalInfoForm"
|
||||||
import accessBooking, {
|
import accessBooking, {
|
||||||
ACCESS_GRANTED,
|
ACCESS_GRANTED,
|
||||||
@@ -34,9 +33,9 @@ import Image from "@/components/Image"
|
|||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
import MyStayProvider from "@/providers/MyStay"
|
import MyStayProvider from "@/providers/MyStay"
|
||||||
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
import * as maskValue from "@/utils/maskValue"
|
import * as maskValue from "@/utils/maskValue"
|
||||||
import { parseRefId } from "@/utils/refId"
|
import { parseRefId } from "@/utils/refId"
|
||||||
import { isValidSession } from "@/utils/session"
|
|
||||||
import { getCurrentWebUrl } from "@/utils/url"
|
import { getCurrentWebUrl } from "@/utils/url"
|
||||||
|
|
||||||
import Tracking from "./tracking"
|
import Tracking from "./tracking"
|
||||||
@@ -64,8 +63,7 @@ export default async function MyStay({
|
|||||||
return notFound()
|
return notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = await auth()
|
const isLoggedIn = await isLoggedInUser()
|
||||||
const isLoggedIn = isValidSession(session)
|
|
||||||
|
|
||||||
const bv = cookies().get("bv")?.value
|
const bv = cookies().get("bv")?.value
|
||||||
let bookingConfirmation
|
let bookingConfirmation
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import {
|
|||||||
getSavedPaymentCardsSafely,
|
getSavedPaymentCardsSafely,
|
||||||
} from "@/lib/trpc/memoizedRequests"
|
} from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
|
||||||
import AdditionalInfoForm from "@/components/HotelReservation/FindMyBooking/AdditionalInfoForm"
|
import AdditionalInfoForm from "@/components/HotelReservation/FindMyBooking/AdditionalInfoForm"
|
||||||
import accessBooking, {
|
import accessBooking, {
|
||||||
ACCESS_GRANTED,
|
ACCESS_GRANTED,
|
||||||
@@ -34,9 +33,9 @@ import Image from "@/components/Image"
|
|||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
import MyStayProvider from "@/providers/MyStay"
|
import MyStayProvider from "@/providers/MyStay"
|
||||||
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
import * as maskValue from "@/utils/maskValue"
|
import * as maskValue from "@/utils/maskValue"
|
||||||
import { parseRefId } from "@/utils/refId"
|
import { parseRefId } from "@/utils/refId"
|
||||||
import { isValidSession } from "@/utils/session"
|
|
||||||
import { getCurrentWebUrl } from "@/utils/url"
|
import { getCurrentWebUrl } from "@/utils/url"
|
||||||
|
|
||||||
import Tracking from "./tracking"
|
import Tracking from "./tracking"
|
||||||
@@ -65,8 +64,7 @@ export default async function MyStay({
|
|||||||
return notFound()
|
return notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = await auth()
|
const isLoggedIn = await isLoggedInUser()
|
||||||
const isLoggedIn = isValidSession(session)
|
|
||||||
|
|
||||||
const bv = cookies().get("bv")?.value
|
const bv = cookies().get("bv")?.value
|
||||||
let bookingConfirmation
|
let bookingConfirmation
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import SurpriseIcon from "@scandic-hotels/design-system/Icons/SurpriseIcon"
|
import SurpriseIcon from "@scandic-hotels/design-system/Icons/SurpriseIcon"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
|
||||||
import Image from "@/components/Image"
|
import Image from "@/components/Image"
|
||||||
import Button from "@/components/TempDesignSystem/Button"
|
import Button from "@/components/TempDesignSystem/Button"
|
||||||
import Link from "@/components/TempDesignSystem/Link"
|
import Link from "@/components/TempDesignSystem/Link"
|
||||||
import BiroScript from "@/components/TempDesignSystem/Text/BiroScript"
|
import BiroScript from "@/components/TempDesignSystem/Text/BiroScript"
|
||||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||||
import { isValidSession } from "@/utils/session"
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
|
|
||||||
import styles from "./joinScandicFriends.module.css"
|
import styles from "./joinScandicFriends.module.css"
|
||||||
|
|
||||||
@@ -20,8 +19,7 @@ interface JoinScandicFriendsProps {
|
|||||||
export default async function JoinScandicFriends({
|
export default async function JoinScandicFriends({
|
||||||
content,
|
content,
|
||||||
}: JoinScandicFriendsProps) {
|
}: JoinScandicFriendsProps) {
|
||||||
const session = await auth()
|
const isLoggedIn = await isLoggedInUser()
|
||||||
const isLoggedIn = isValidSession(session)
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
import { login } from "@/constants/routes/handleAuth"
|
import { login } from "@/constants/routes/handleAuth"
|
||||||
import { signup } from "@/constants/routes/signup"
|
import { signup } from "@/constants/routes/signup"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
|
||||||
import Card from "@/components/TempDesignSystem/Card"
|
import Card from "@/components/TempDesignSystem/Card"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
import { getLang } from "@/i18n/serverContext"
|
import { getLang } from "@/i18n/serverContext"
|
||||||
import { isValidSession } from "@/utils/session"
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
|
|
||||||
import styles from "./authCard.module.css"
|
import styles from "./authCard.module.css"
|
||||||
|
|
||||||
export default async function EmployeeBenefitsAuthCard() {
|
export default async function EmployeeBenefitsAuthCard() {
|
||||||
const session = await auth()
|
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
|
|
||||||
const lang = getLang()
|
const lang = getLang()
|
||||||
|
|
||||||
if (isValidSession(session)) {
|
const isLoggedIn = await isLoggedInUser()
|
||||||
|
|
||||||
|
if (isLoggedIn) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { getHeader } from "@/lib/trpc/memoizedRequests"
|
import { getHeader } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
import { isValidSession } from "@/utils/session"
|
|
||||||
|
|
||||||
import MobileMenu from "../MobileMenu"
|
import MobileMenu from "../MobileMenu"
|
||||||
|
|
||||||
@@ -10,17 +9,15 @@ export default async function MobileMenuWrapper({
|
|||||||
}: React.PropsWithChildren) {
|
}: React.PropsWithChildren) {
|
||||||
// preloaded
|
// preloaded
|
||||||
const header = await getHeader()
|
const header = await getHeader()
|
||||||
const session = await auth()
|
|
||||||
|
|
||||||
if (!header) {
|
if (!header) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isLoggedIn = await isLoggedInUser()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MobileMenu
|
<MobileMenu topLink={header.data.topLink} isLoggedIn={isLoggedIn}>
|
||||||
topLink={header.data.topLink}
|
|
||||||
isLoggedIn={isValidSession(session)}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</MobileMenu>
|
</MobileMenu>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,14 +5,13 @@ import {
|
|||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { getHeader } from "@/lib/trpc/memoizedRequests"
|
import { getHeader } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
|
||||||
import { IconName } from "@/components/Icons/iconName"
|
import { IconName } from "@/components/Icons/iconName"
|
||||||
import LanguageSwitcher from "@/components/LanguageSwitcher"
|
import LanguageSwitcher from "@/components/LanguageSwitcher"
|
||||||
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
||||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
import { getLang } from "@/i18n/serverContext"
|
import { getLang } from "@/i18n/serverContext"
|
||||||
import { isValidSession } from "@/utils/session"
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
import { getCurrentWebUrl } from "@/utils/url"
|
import { getCurrentWebUrl } from "@/utils/url"
|
||||||
|
|
||||||
import HeaderLink from "../HeaderLink"
|
import HeaderLink from "../HeaderLink"
|
||||||
@@ -25,8 +24,7 @@ export default async function TopMenu() {
|
|||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
// both preloaded
|
// both preloaded
|
||||||
const header = await getHeader()
|
const header = await getHeader()
|
||||||
const session = await auth()
|
const isLoggedIn = await isLoggedInUser()
|
||||||
const isLoggedIn = isValidSession(session)
|
|
||||||
|
|
||||||
if (!header) {
|
if (!header) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { getSavedPaymentCardsSafely } from "@/lib/trpc/memoizedRequests"
|
import { getSavedPaymentCardsSafely } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
import { isValidSession } from "@/utils/session"
|
|
||||||
|
|
||||||
import PaymentClient from "./PaymentClient"
|
import PaymentClient from "./PaymentClient"
|
||||||
|
|
||||||
@@ -14,8 +13,7 @@ export default async function Payment({
|
|||||||
const savedCreditCards = await getSavedPaymentCardsSafely({
|
const savedCreditCards = await getSavedPaymentCardsSafely({
|
||||||
supportedCards,
|
supportedCards,
|
||||||
})
|
})
|
||||||
const session = await auth()
|
const isUserLoggedIn = await isLoggedInUser()
|
||||||
const isUserLoggedIn = isValidSession(session)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PaymentClient
|
<PaymentClient
|
||||||
|
|||||||
@@ -12,11 +12,10 @@ import {
|
|||||||
getProfileSafely,
|
getProfileSafely,
|
||||||
} from "@/lib/trpc/memoizedRequests"
|
} from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
import * as maskValue from "@/utils/maskValue"
|
import * as maskValue from "@/utils/maskValue"
|
||||||
import { parseRefId } from "@/utils/refId"
|
import { parseRefId } from "@/utils/refId"
|
||||||
import { isValidSession } from "@/utils/session"
|
|
||||||
|
|
||||||
import AdditionalInfoForm from "../../FindMyBooking/AdditionalInfoForm"
|
import AdditionalInfoForm from "../../FindMyBooking/AdditionalInfoForm"
|
||||||
import accessBooking, {
|
import accessBooking, {
|
||||||
@@ -41,8 +40,7 @@ export async function Receipt({ refId }: { refId: string }) {
|
|||||||
return notFound()
|
return notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = await auth()
|
const isLoggedIn = await isLoggedInUser()
|
||||||
const isLoggedIn = isValidSession(session)
|
|
||||||
|
|
||||||
const bv = cookies().get("bv")?.value
|
const bv = cookies().get("bv")?.value
|
||||||
let bookingConfirmation
|
let bookingConfirmation
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
|
||||||
import { ScandicFriends } from "@/components/Levels"
|
import { ScandicFriends } from "@/components/Levels"
|
||||||
import LoginButton from "@/components/LoginButton"
|
import LoginButton from "@/components/LoginButton"
|
||||||
import Button from "@/components/TempDesignSystem/Button"
|
import Button from "@/components/TempDesignSystem/Button"
|
||||||
@@ -8,7 +7,7 @@ import Link from "@/components/TempDesignSystem/Link"
|
|||||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
import { isValidSession } from "@/utils/session"
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
|
|
||||||
import Contact from "./Contact"
|
import Contact from "./Contact"
|
||||||
import ReadMore from "./ReadMore"
|
import ReadMore from "./ReadMore"
|
||||||
@@ -20,9 +19,9 @@ import type { JoinLoyaltyContactProps } from "@/types/components/sidebar/joinLoy
|
|||||||
export default async function JoinLoyaltyContact({
|
export default async function JoinLoyaltyContact({
|
||||||
block,
|
block,
|
||||||
}: JoinLoyaltyContactProps) {
|
}: JoinLoyaltyContactProps) {
|
||||||
const [intl, session] = await Promise.all([getIntl(), auth()])
|
const [intl, isLoggedIn] = await Promise.all([getIntl(), isLoggedInUser()])
|
||||||
|
|
||||||
if (isValidSession(session)) {
|
if (isLoggedIn) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import { Suspense } from "react"
|
import { Suspense } from "react"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
|
||||||
import MyPagesSidebar from "@/components/MyPages/Sidebar"
|
import MyPagesSidebar from "@/components/MyPages/Sidebar"
|
||||||
import { isValidSession } from "@/utils/session"
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
|
|
||||||
import SidebarNavigationSkeleton from "../MyPages/Sidebar/SidebarNavigationSkeleton"
|
import SidebarNavigationSkeleton from "../MyPages/Sidebar/SidebarNavigationSkeleton"
|
||||||
|
|
||||||
export default async function MyPagesNavigation() {
|
export default async function MyPagesNavigation() {
|
||||||
const session = await auth()
|
const isLoggedIn = await isLoggedInUser()
|
||||||
if (!isValidSession(session)) {
|
if (!isLoggedIn) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return (
|
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