refactor: update logic

This commit is contained in:
Mauricio Siu
2025-02-15 19:35:22 -06:00
parent 1c5cc5a0db
commit 8b71f963cc
5 changed files with 19 additions and 16 deletions

View File

@@ -51,7 +51,7 @@ export const GenerateToken = () => {
<Label>Token</Label> <Label>Token</Label>
<ToggleVisibilityInput <ToggleVisibilityInput
placeholder="Token" placeholder="Token"
value={data?.token || ""} value={data?.user?.token || ""}
disabled disabled
/> />
</div> </div>

View File

@@ -73,9 +73,9 @@ export const ProfileForm = () => {
const form = useForm<Profile>({ const form = useForm<Profile>({
defaultValues: { defaultValues: {
email: data?.email || "", email: data?.user?.email || "",
password: "", password: "",
image: data?.image || "", image: data?.user?.image || "",
currentPassword: "", currentPassword: "",
}, },
resolver: zodResolver(profileSchema), resolver: zodResolver(profileSchema),
@@ -84,14 +84,14 @@ export const ProfileForm = () => {
useEffect(() => { useEffect(() => {
if (data) { if (data) {
form.reset({ form.reset({
email: data?.email || "", email: data?.user?.email || "",
password: "", password: "",
image: data?.image || "", image: data?.user?.image || "",
currentPassword: "", currentPassword: "",
}); });
if (data.email) { if (data.user.email) {
generateSHA256Hash(data.email).then((hash) => { generateSHA256Hash(data.user.email).then((hash) => {
setGravatarHash(hash); setGravatarHash(hash);
}); });
} }

View File

@@ -51,12 +51,15 @@ export const UserNav = () => {
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground" className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
> >
<Avatar className="h-8 w-8 rounded-lg"> <Avatar className="h-8 w-8 rounded-lg">
<AvatarImage src={data?.image || ""} alt={data?.image || ""} /> <AvatarImage
src={data?.user?.image || ""}
alt={data?.user?.image || ""}
/>
<AvatarFallback className="rounded-lg">CN</AvatarFallback> <AvatarFallback className="rounded-lg">CN</AvatarFallback>
</Avatar> </Avatar>
<div className="grid flex-1 text-left text-sm leading-tight"> <div className="grid flex-1 text-left text-sm leading-tight">
<span className="truncate font-semibold">Account</span> <span className="truncate font-semibold">Account</span>
<span className="truncate text-xs">{data?.email}</span> <span className="truncate text-xs">{data?.user?.email}</span>
</div> </div>
<ChevronsUpDown className="ml-auto size-4" /> <ChevronsUpDown className="ml-auto size-4" />
</SidebarMenuButton> </SidebarMenuButton>
@@ -71,7 +74,7 @@ export const UserNav = () => {
<DropdownMenuLabel className="flex flex-col"> <DropdownMenuLabel className="flex flex-col">
My Account My Account
<span className="text-xs font-normal text-muted-foreground"> <span className="text-xs font-normal text-muted-foreground">
{data?.email} {data?.user?.email}
</span> </span>
</DropdownMenuLabel> </DropdownMenuLabel>
<ModeToggle /> <ModeToggle />

View File

@@ -19,7 +19,7 @@ const Page = () => {
authId: data?.id || "", authId: data?.id || "",
}, },
{ {
enabled: !!data?.id && data?.role === "member", enabled: !!data?.id && data?.role === "user",
}, },
); );
@@ -62,7 +62,7 @@ export async function getServerSideProps(
await helpers.settings.isCloud.prefetch(); await helpers.settings.isCloud.prefetch();
await helpers.auth.get.prefetch(); await helpers.auth.get.prefetch();
if (user?.role === "member") { if (user?.role === "user") {
await helpers.user.byAuthId.prefetch({ await helpers.user.byAuthId.prefetch({
authId: user.authId, authId: user.authId,
}); });

View File

@@ -31,7 +31,7 @@ import { ZodError } from "zod";
*/ */
interface CreateContextOptions { interface CreateContextOptions {
user: (User & { rol: "admin" | "user"; ownerId: string }) | null; user: (User & { rol: "member" | "admin" | "owner"; ownerId: string }) | null;
session: (Session & { activeOrganizationId?: string }) | null; session: (Session & { activeOrganizationId?: string }) | null;
req: CreateNextContextOptions["req"]; req: CreateNextContextOptions["req"];
res: CreateNextContextOptions["res"]; res: CreateNextContextOptions["res"];
@@ -91,7 +91,7 @@ export const createTRPCContext = async (opts: CreateNextContextOptions) => {
? { ? {
...user, ...user,
email: user.email, email: user.email,
rol: user.role as "admin" | "user", rol: user.role as "owner" | "member" | "admin",
id: user.id, id: user.id,
ownerId: user.ownerId, ownerId: user.ownerId,
} }
@@ -188,7 +188,7 @@ export const uploadProcedure = async (opts: any) => {
}; };
export const cliProcedure = t.procedure.use(({ ctx, next }) => { export const cliProcedure = t.procedure.use(({ ctx, next }) => {
if (!ctx.session || !ctx.user || ctx.user.rol !== "admin") { if (!ctx.session || !ctx.user || ctx.user.rol !== "owner") {
throw new TRPCError({ code: "UNAUTHORIZED" }); throw new TRPCError({ code: "UNAUTHORIZED" });
} }
return next({ return next({
@@ -202,7 +202,7 @@ export const cliProcedure = t.procedure.use(({ ctx, next }) => {
}); });
export const adminProcedure = t.procedure.use(({ ctx, next }) => { export const adminProcedure = t.procedure.use(({ ctx, next }) => {
if (!ctx.session || !ctx.user || ctx.user.rol !== "admin") { if (!ctx.session || !ctx.user || ctx.user.rol !== "owner") {
throw new TRPCError({ code: "UNAUTHORIZED" }); throw new TRPCError({ code: "UNAUTHORIZED" });
} }
return next({ return next({