Merged in fix/check-valid-session (pull request #1502)
Fix/check valid session * fix:session - check if valid session * Refactor Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -4,6 +4,8 @@ import { z } from "zod"
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { safeProtectedProcedure } from "@/server/trpc"
|
||||
|
||||
import { isValidSession } from "@/utils/session"
|
||||
|
||||
import { getVerifiedUser } from "../../user/query"
|
||||
import { getPrimaryLinks } from "./getPrimaryLinks"
|
||||
import { getSecondaryLinks } from "./getSecondaryLinks"
|
||||
@@ -24,7 +26,7 @@ export const myPagesNavigation = safeProtectedProcedure
|
||||
primaryLinks: MyPagesLink[]
|
||||
secondaryLinks: MyPagesLink[]
|
||||
} | null> => {
|
||||
if (!ctx.session) {
|
||||
if (!isValidSession(ctx.session)) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
|
||||
import { cache } from "@/utils/cache"
|
||||
import * as maskValue from "@/utils/maskValue"
|
||||
import { isValidSession } from "@/utils/session"
|
||||
import { getFriendsMembership, getMembershipCards } from "@/utils/user"
|
||||
|
||||
import {
|
||||
@@ -309,7 +310,7 @@ export const userQueryRouter = router({
|
||||
return parsedUser(data.data, ctx.isMFA)
|
||||
}),
|
||||
getSafely: safeProtectedProcedure.query(async function getUser({ ctx }) {
|
||||
if (!ctx.session) {
|
||||
if (!isValidSession(ctx.session)) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -322,7 +323,7 @@ export const userQueryRouter = router({
|
||||
return parsedUser(data.data, true)
|
||||
}),
|
||||
name: safeProtectedProcedure.query(async function ({ ctx }) {
|
||||
if (!ctx.session) {
|
||||
if (!isValidSession(ctx.session)) {
|
||||
return null
|
||||
}
|
||||
const verifiedData = await getVerifiedUser({ session: ctx.session })
|
||||
@@ -345,7 +346,7 @@ export const userQueryRouter = router({
|
||||
return membershipLevel
|
||||
}),
|
||||
safeMembershipLevel: safeProtectedProcedure.query(async function ({ ctx }) {
|
||||
if (!ctx.session) {
|
||||
if (!isValidSession(ctx.session)) {
|
||||
return null
|
||||
}
|
||||
const verifiedData = await getVerifiedUser({ session: ctx.session })
|
||||
@@ -362,7 +363,7 @@ export const userQueryRouter = router({
|
||||
loginStatus: "Non-logged in",
|
||||
}
|
||||
|
||||
if (!ctx.session) {
|
||||
if (!isValidSession(ctx.session)) {
|
||||
return notLoggedInUserTrackingData
|
||||
}
|
||||
const verifiedUserData = await getVerifiedUser({ session: ctx.session })
|
||||
@@ -761,7 +762,7 @@ export const userQueryRouter = router({
|
||||
safePaymentCards: safeProtectedProcedure
|
||||
.input(getSavedPaymentCardsInput)
|
||||
.query(async function ({ ctx, input }) {
|
||||
if (!ctx.session) {
|
||||
if (!isValidSession(ctx.session)) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import "server-only"
|
||||
|
||||
import type { Session } from "next-auth"
|
||||
|
||||
export function isValidSession(session: Session | null) {
|
||||
export function isValidSession(session: Session | null): session is Session {
|
||||
if (!session) {
|
||||
console.log("No session available (user not authenticated).")
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user