fix account page data access
This commit is contained in:
@@ -13,19 +13,12 @@ import AddImageToS3 from "~/lib/s3upload";
|
|||||||
import { validatePassword, isValidEmail } from "~/lib/validation";
|
import { validatePassword, isValidEmail } from "~/lib/validation";
|
||||||
import { TerminalSplash } from "~/components/TerminalSplash";
|
import { TerminalSplash } from "~/components/TerminalSplash";
|
||||||
|
|
||||||
type UserProfile = {
|
import type { UserProfile } from "~/types/user";
|
||||||
id: string;
|
|
||||||
email: string | null;
|
|
||||||
emailVerified: boolean;
|
|
||||||
displayName: string | null;
|
|
||||||
image: string | null;
|
|
||||||
provider: "email" | "google" | "github" | null;
|
|
||||||
hasPassword: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getUserProfile = query(async (): Promise<UserProfile | null> => {
|
const getUserProfile = query(async (): Promise<UserProfile | null> => {
|
||||||
"use server";
|
"use server";
|
||||||
const { getUserID, ConnectionFactory } = await import("~/server/utils");
|
const { getUserID, ConnectionFactory } = await import("~/server/utils");
|
||||||
|
const { toUserProfile } = await import("~/types/user");
|
||||||
const event = getEvent()!;
|
const event = getEvent()!;
|
||||||
|
|
||||||
const userId = await getUserID(event);
|
const userId = await getUserID(event);
|
||||||
@@ -45,17 +38,7 @@ const getUserProfile = query(async (): Promise<UserProfile | null> => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user = res.rows[0] as any;
|
const user = res.rows[0] as any;
|
||||||
|
return toUserProfile(user);
|
||||||
// Transform to UserProfile type
|
|
||||||
return {
|
|
||||||
id: user.id,
|
|
||||||
email: user.email || null,
|
|
||||||
emailVerified: Boolean(user.emailVerified),
|
|
||||||
displayName: user.displayName || null,
|
|
||||||
image: user.image || null,
|
|
||||||
provider: user.provider || null,
|
|
||||||
hasPassword: Boolean(user.password)
|
|
||||||
};
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to fetch user profile:", err);
|
console.error("Failed to fetch user profile:", err);
|
||||||
throw redirect("/login");
|
throw redirect("/login");
|
||||||
@@ -305,7 +288,11 @@ export default function AccountPage() {
|
|||||||
const response = await fetch("/api/trpc/user.changePassword", {
|
const response = await fetch("/api/trpc/user.changePassword", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ oldPassword, newPassword })
|
body: JSON.stringify({
|
||||||
|
oldPassword,
|
||||||
|
newPassword,
|
||||||
|
newPasswordConfirmation: newPasswordConf
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
@@ -350,7 +337,10 @@ export default function AccountPage() {
|
|||||||
const response = await fetch("/api/trpc/user.setPassword", {
|
const response = await fetch("/api/trpc/user.setPassword", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ password: newPassword })
|
body: JSON.stringify({
|
||||||
|
newPassword,
|
||||||
|
newPasswordConfirmation: newPasswordConf
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|||||||
Reference in New Issue
Block a user