Skip to content

Commit

Permalink
Merge pull request #49 from hack4impact-calpoly/31-volunteer
Browse files Browse the repository at this point in the history
31 -  Redirect and add new users to database
  • Loading branch information
kaseyliu authored Mar 4, 2025
2 parents fa5155d + 5ea28f3 commit ba87b42
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# make sure to add .env.local to .gitignore!!
MONGO_URI={mongo-uri-here}
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_YW11c2luZy1zZWFzbmFpbC01OS5jbGVyay5hY2NvdW50cy5kZXYk
NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL=/signupredirect
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
marginLeft: pathName !== "/login" && pathName !== "/signup" ? "15rem" : "0",
}}
>
{/*<ProfileCard/>*/}
<ProfileCard />
{children}
</main>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Box, Progress, Tabs, TabList, TabPanels, Tab, TabPanel, Flex } from "@c
import { GoRows } from "react-icons/go";
import { PiRows } from "react-icons/pi";
import { useUser } from "@clerk/nextjs";
import ProfileCard from "@/components/ProfileCard";

export default function Home() {
const { user } = useUser();
Expand Down
41 changes: 41 additions & 0 deletions src/app/signupredirect/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use client";

import { useEffect, useState } from "react";
import { useUser } from "@clerk/nextjs"; // Import Clerk's hook
import { useRouter } from "next/navigation";

export default function SignupRedirect() {
const { user, isLoaded } = useUser();
const router = useRouter();
const [error, setError] = useState(null);

useEffect(() => {
if (!isLoaded) return;

if (user) {
const submitUserInfo = async () => {
try {
const response = await fetch("/api/user", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: user.fullName,
email: user.primaryEmailAddress?.emailAddress,
role: "Volunteer",
}),
});

if (!response.ok) throw new Error("Failed to add user");

router.push("/");
} catch (err: any) {
setError(err.message);
}
};

submitUserInfo();
}
}, [user, isLoaded, router]);
}
4 changes: 2 additions & 2 deletions src/components/ProfileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default function ProfileCard() {
<SignedIn>
<Flex justify="flex-end" gap="4" bg="#F4F1E8">
{/* <div className={styles.profileCardBox} onClick={() => router.push("/userProfile")}> */}
<Box borderWidth="3px" padding={10} rounded="10" m="20px" bg="white">
<Flex align="center" gap={10}>
<Box rounded="10" padding="20px" m="20px" bg="white">
<Flex align="center" gap={5}>
<UserButton></UserButton>
{/* TODO: Once funcionality is working for profile card drop down then remove user button
and uncomment the image below */}
Expand Down
3 changes: 1 addition & 2 deletions src/database/userSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import mongoose, { Schema } from "mongoose";
const UserSchema = new Schema({
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
phoneNumber: { type: String, required: true },
phoneNumber: { type: String, required: false },
role: { type: String, required: true },
});

Expand Down

0 comments on commit ba87b42

Please sign in to comment.