mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-18 10:09:49 -06:00
fix: onboarding ending in endless loop because of validation error (#1745)
This commit is contained in:
@@ -14,10 +14,11 @@ import { Prisma } from "@prisma/client";
|
||||
import { unstable_cache } from "next/cache";
|
||||
import { z } from "zod";
|
||||
import { SERVICES_REVALIDATION_INTERVAL } from "../constants";
|
||||
import { updateMembership } from "../membership/service";
|
||||
import { deleteTeam } from "../team/service";
|
||||
import { validateInputs } from "../utils/validate";
|
||||
import { profileCache } from "./cache";
|
||||
import { updateMembership } from "../membership/service";
|
||||
import { formatProfileDateFields } from "./util";
|
||||
|
||||
const responseSelection = {
|
||||
id: true,
|
||||
@@ -34,8 +35,8 @@ const responseSelection = {
|
||||
};
|
||||
|
||||
// function to retrive basic information about a user's profile
|
||||
export const getProfile = async (id: string): Promise<TProfile | null> =>
|
||||
unstable_cache(
|
||||
export const getProfile = async (id: string): Promise<TProfile | null> => {
|
||||
const profile = await unstable_cache(
|
||||
async () => {
|
||||
validateInputs([id, ZId]);
|
||||
|
||||
@@ -67,8 +68,18 @@ export const getProfile = async (id: string): Promise<TProfile | null> =>
|
||||
}
|
||||
)();
|
||||
|
||||
export const getProfileByEmail = async (email: string): Promise<TProfile | null> =>
|
||||
unstable_cache(
|
||||
if (!profile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
...profile,
|
||||
...formatProfileDateFields(profile),
|
||||
} as TProfile;
|
||||
};
|
||||
|
||||
export const getProfileByEmail = async (email: string): Promise<TProfile | null> => {
|
||||
const profile = await unstable_cache(
|
||||
async () => {
|
||||
validateInputs([email, z.string().email()]);
|
||||
|
||||
@@ -100,6 +111,16 @@ export const getProfileByEmail = async (email: string): Promise<TProfile | null>
|
||||
}
|
||||
)();
|
||||
|
||||
if (!profile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
...profile,
|
||||
...formatProfileDateFields(profile),
|
||||
} as TProfile;
|
||||
};
|
||||
|
||||
const getAdminMemberships = (memberships: TMembership[]): TMembership[] =>
|
||||
memberships.filter((membership) => membership.role === "admin");
|
||||
|
||||
|
||||
15
packages/lib/profile/util.ts
Normal file
15
packages/lib/profile/util.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { TProfile } from "@formbricks/types/profile";
|
||||
|
||||
export const formatProfileDateFields = (profile: TProfile): TProfile => {
|
||||
if (typeof profile.createdAt === "string") {
|
||||
profile.createdAt = new Date(profile.createdAt);
|
||||
}
|
||||
if (typeof profile.updatedAt === "string") {
|
||||
profile.updatedAt = new Date(profile.updatedAt);
|
||||
}
|
||||
if (typeof profile.emailVerified === "string") {
|
||||
profile.emailVerified = new Date(profile.emailVerified);
|
||||
}
|
||||
|
||||
return profile;
|
||||
};
|
||||
@@ -1,8 +1,8 @@
|
||||
import "server-only";
|
||||
|
||||
import { TResponseDates, TResponseTtc } from "@formbricks/types/responses";
|
||||
import { TResponse, TResponseTtc } from "@formbricks/types/responses";
|
||||
|
||||
export const formatResponseDateFields = (response: TResponseDates): TResponseDates => {
|
||||
export const formatResponseDateFields = (response: TResponse): TResponse => {
|
||||
if (typeof response.createdAt === "string") {
|
||||
response.createdAt = new Date(response.createdAt);
|
||||
}
|
||||
|
||||
@@ -66,12 +66,6 @@ export const ZResponse = z.object({
|
||||
|
||||
export type TResponse = z.infer<typeof ZResponse>;
|
||||
|
||||
export type TResponseDates = {
|
||||
createdAt: TResponse["createdAt"];
|
||||
updatedAt: TResponse["updatedAt"];
|
||||
notes: TResponse["notes"];
|
||||
};
|
||||
|
||||
export const ZResponseInput = z.object({
|
||||
environmentId: z.string().cuid2(),
|
||||
surveyId: z.string().cuid2(),
|
||||
|
||||
Reference in New Issue
Block a user