Merged in feat/masked-values (pull request #489)

feat: handle masked values only based on MFA

Approved-by: Michael Zetterberg
Approved-by: Arvid Norlin
This commit is contained in:
Simon.Emanuelsson
2024-08-26 09:19:02 +00:00
committed by Michael Zetterberg
3 changed files with 14 additions and 15 deletions

View File

@@ -10,7 +10,7 @@ export default async function EditProfileSlot({
}: PageArgs<LangParams>) {
setLang(params.lang)
const user = await serverClient().user.get({ mask: false })
const user = await serverClient().user.get()
if (!user || "error" in user) {
return null
}

View File

@@ -1,12 +1,6 @@
import { z } from "zod"
// Query
export const getUserInputSchema = z
.object({
mask: z.boolean().default(true),
})
.default({})
export const staysInput = z
.object({
cursor: z

View File

@@ -12,11 +12,7 @@ import * as maskValue from "@/utils/maskValue"
import { getMembership, getMembershipCards } from "@/utils/user"
import encryptValue from "../utils/encryptValue"
import {
friendTransactionsInput,
getUserInputSchema,
staysInput,
} from "./input"
import { friendTransactionsInput, staysInput } from "./input"
import {
creditCardsSchema,
FriendTransaction,
@@ -192,8 +188,17 @@ async function updateStaysBookingUrl(
export const userQueryRouter = router({
get: protectedProcedure
.input(getUserInputSchema)
.query(async function getUser({ ctx, input }) {
.use(async function (opts) {
return opts.next({
ctx: {
...opts.ctx,
isMFA:
opts.ctx.session.token.mfa_scope &&
opts.ctx.session.token.mfa_expires_at > Date.now(),
},
})
})
.query(async function getUser({ ctx }) {
const data = await getVerifiedUser({ session: ctx.session })
if (!data) {
@@ -230,7 +235,7 @@ export const userQueryRouter = router({
profileId: verifiedData.data.profileId,
}
if (input.mask) {
if (!ctx.isMFA) {
if (user.address.city) {
user.address.city = maskValue.text(user.address.city)
}