Skip to content

Commit

Permalink
Added default user pfp
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit20v committed Aug 1, 2024
1 parent c13cb9d commit d8d684e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/routes/sign_in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ import {prisma} from "~/.server/db";
import {Prisma} from "@prisma/client";
import {encrypt} from "~/.server/auth";
import {commitSession, getSession} from "~/session";
import fs from "fs";

const DEFAULT_AVATAR_PATH = "./public/default.jpg";
const USER_AVATAR_DIR = "./public/uavatar";

const setDefaultAvatar = (username: string) => {
try {
if (!fs.existsSync(USER_AVATAR_DIR)) {
fs.mkdirSync(USER_AVATAR_DIR, { recursive: true }); // recursive: true ensure that the directory is created
}

const userAvatarPath = `${USER_AVATAR_DIR}/${username}.jpg`;
fs.copyFileSync(DEFAULT_AVATAR_PATH, userAvatarPath);

console.log(`Default avatar set for user: ${username}`);
} catch (error) {
console.error("Error setting default avatar:", error);
}
};


export const action = async ({request}: ActionFunctionArgs) => {
const formData = await request.formData();
Expand All @@ -24,9 +44,11 @@ export const action = async ({request}: ActionFunctionArgs) => {
});
console.log("USER CREATED", createdUser.username);

setDefaultAvatar(username_lower)
const session = await getSession();
session.set("user", username_lower);


return redirect("/", {
headers: {
"Set-Cookie": await commitSession(session),
Expand Down
Binary file added public/default.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d8d684e

Please sign in to comment.