Skip to content

Commit

Permalink
Changing to next auth v5
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyG11 committed Apr 7, 2024
1 parent 2d945b6 commit 2b5745c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
6 changes: 3 additions & 3 deletions components/Profile/Edit/EditBlocks/Edit.profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Button } from "@/components/shared/Button";
import TextField from "@/components/shared/TextField";
import InputField from "@/components/shared/InputField";
import { updateUserProfilePicture } from "@/libs/actions/profile.actions";
import { profileImageSchema } from "@/schemas/ProfileSchema";
import { ProfileImageSchema } from "@/schemas/ProfileSchema";

interface GeneralProps {
profile: User;
Expand All @@ -25,11 +25,11 @@ export const EditProfileBlock: React.FC<GeneralProps> = ({ profile }) => {
defaultValues: {
image: "",
},
resolver: zodResolver(profileImageSchema),
resolver: zodResolver(ProfileImageSchema),
});
const [files, setFiles] = useState<File[]>([]);

const onSubmit = async (data: z.infer<typeof profileImageSchema>) => {
const onSubmit = async (data: z.infer<typeof ProfileImageSchema>) => {
console.log("Form submitted");

try {
Expand Down
35 changes: 25 additions & 10 deletions libs/actions/profile.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,35 @@ import { prisma } from "@/libs/prisma";
// import { sendVerificationEmail } from "@/lib/mail";
// import { generateVerificationToken } from "@/lib/tokens";

import axios from "axios";
import { getUserByEmail } from "@/libs/auth";
import { SignUpSchema } from "@/schemas/ProfileSchema";
import { currentUser } from "../auth/getCurrentUser";
import { SignUpSchema, ProfileImageSchema } from "@/schemas/ProfileSchema";
import { revalidatePath } from "next/cache";

export const updateUserProfilePicture = async (data: { image: string }) => {
const validatedFields = SignUpSchema.safeParse(data);
if (!validatedFields.success) {
console.log(validatedFields.error);
}
export const updateUserProfilePicture = async (
values: z.infer<typeof ProfileImageSchema>
) => {
try {
const res = await axios.get(`http://localhost:3000/api/profile`, {
data,
const user = await currentUser();
if (!user) {
throw new Error("User not found!");
}
const validatedFields = ProfileImageSchema.safeParse(values);
if (!validatedFields.success) {
console.log(validatedFields.error);
return { error: "Invalid fields!" };
}
const { image } = validatedFields.data;
const updateProfile = await prisma.user.update({
where: {
id: user.id,
},
data: {
image,
},
});
return res.data;
console.log(updateProfile);
revalidatePath("/profile/edit");
} catch (error: any) {
console.error("ERROR SERV", error.message);
}
Expand Down
6 changes: 4 additions & 2 deletions schemas/ProfileSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const SigninSchema = z.object({
code: z.optional(z.string()),
});

export const profileImageSchema = z.object({
image: z.string().url(),
export const ProfileImageSchema = z.object({
image: z.string().url({
message: "Invalid image url",
}),
});

0 comments on commit 2b5745c

Please sign in to comment.