Merged in feat/sw-3610-basicProfile (pull request #3144)
Feat(SW-3610): basic profile endpoint on protected layouts * Basic profile in protected layouts * . Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -6,7 +6,7 @@ import { redirect } from "next/navigation"
|
|||||||
import { logger } from "@scandic-hotels/common/logger"
|
import { logger } from "@scandic-hotels/common/logger"
|
||||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||||
|
|
||||||
import { getProfile } from "@/lib/trpc/memoizedRequests"
|
import { getBasicProfile } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ export default async function Layout(props: LayoutProps<"/[lang]/webview">) {
|
|||||||
|
|
||||||
const { children } = props
|
const { children } = props
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
const [user, error] = await safeTry(getProfile())
|
const [user, error] = await safeTry(getBasicProfile())
|
||||||
|
|
||||||
if (!user && !error) {
|
if (!user && !error) {
|
||||||
logger.debug(`[webview:page] unable to load user`)
|
logger.debug(`[webview:page] unable to load user`)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { logger } from "@scandic-hotels/common/logger"
|
|||||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||||
import { isValidSession } from "@scandic-hotels/trpc/utils/session"
|
import { isValidSession } from "@scandic-hotels/trpc/utils/session"
|
||||||
|
|
||||||
import { getProfile } from "@/lib/trpc/memoizedRequests"
|
import { getBasicProfile } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import { auth } from "@/auth"
|
import { auth } from "@/auth"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
@@ -35,7 +35,7 @@ export async function ProtectedLayout({ children }: React.PropsWithChildren) {
|
|||||||
redirect(redirectURL)
|
redirect(redirectURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
const [user, error] = await safeTry(getProfile())
|
const [user, error] = await safeTry(getBasicProfile())
|
||||||
|
|
||||||
if (error instanceof TRPCError && error.code === "INTERNAL_SERVER_ERROR") {
|
if (error instanceof TRPCError && error.code === "INTERNAL_SERVER_ERROR") {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ export const getProfile = cache(async function getMemoizedProfile() {
|
|||||||
return caller.user.get()
|
return caller.user.get()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const getBasicProfile = cache(async function getMemoizedBasicProfile() {
|
||||||
|
const caller = await serverClient()
|
||||||
|
return caller.user.getBasic()
|
||||||
|
})
|
||||||
|
|
||||||
export const getProfileSafely = cache(
|
export const getProfileSafely = cache(
|
||||||
async function getMemoizedProfileSafely() {
|
async function getMemoizedProfileSafely() {
|
||||||
const caller = await serverClient()
|
const caller = await serverClient()
|
||||||
|
|||||||
@@ -64,6 +64,14 @@ export const userQueryRouter = router({
|
|||||||
|
|
||||||
return parsedUser(user, false)
|
return parsedUser(user, false)
|
||||||
}),
|
}),
|
||||||
|
getBasic: protectedProcedure.query(async function getBasicUser({ ctx }) {
|
||||||
|
const user = await ctx.getScandicBasicUser()
|
||||||
|
if (!user) {
|
||||||
|
throw notFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
return user
|
||||||
|
}),
|
||||||
getWithExtendedPartnerData: safeProtectedProcedure.query(
|
getWithExtendedPartnerData: safeProtectedProcedure.query(
|
||||||
async function getUser({ ctx }) {
|
async function getUser({ ctx }) {
|
||||||
if (!isValidSession(ctx.session)) {
|
if (!isValidSession(ctx.session)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user