Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signup Routing #33

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/rest/authRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ authRouter.post("/signup", signupRequestValidator, async (req, res) => {
firstName: req.body.firstName,
lastName: req.body.lastName,
email: req.body.email,
role: "Facilitator",
role: req.body.role,
password: req.body.password,
});

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/APIClients/AuthAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ const signup = async (
lastName: string,
email: string,
password: string,
role: string, // Added role parameter
): Promise<AuthenticatedUser> => {
try {
const { data } = await baseAPIClient.post(
"/auth/signup",
{ firstName, lastName, email, password },
{ firstName, lastName, email, password, role }, // Added role to request body
{ withCredentials: true },
);
localStorage.setItem(AUTHENTICATED_USER_KEY, JSON.stringify(data));
Expand All @@ -72,7 +73,6 @@ const signup = async (
return null;
}
};

const resetPassword = async (email: string | undefined): Promise<boolean> => {
const bearerToken = `Bearer ${getLocalStorageObjProperty(
AUTHENTICATED_USER_KEY,
Expand Down
18 changes: 15 additions & 3 deletions frontend/src/components/auth/Signup.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useContext, useState } from "react";
import { Redirect } from "react-router-dom";
import { Redirect, useLocation } from "react-router-dom";

import authAPIClient from "../../APIClients/AuthAPIClient";
import { HOME_PAGE } from "../../constants/Routes";
import { HOME_PAGE, WELCOME_PAGE } from "../../constants/Routes";
import AuthContext from "../../contexts/AuthContext";
import { AuthenticatedUser } from "../../types/AuthTypes";
import { capitalizeFirstLetter } from "../../utils/StringUtils";

const Signup = (): React.ReactElement => {
const { authenticatedUser, setAuthenticatedUser } = useContext(AuthContext);
Expand All @@ -13,12 +14,23 @@ const Signup = (): React.ReactElement => {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");

const location = useLocation();

// Extract query parameters from the URL
const params = new URLSearchParams(location.search);
const role = params.get("role");

if (role !== "facilitator") {
return <Redirect to={WELCOME_PAGE} />;
}

const onSignupClick = async () => {
const user: AuthenticatedUser = await authAPIClient.signup(
firstName,
lastName,
email,
password,
capitalizeFirstLetter(role),
);
setAuthenticatedUser(user);
};
Expand All @@ -29,7 +41,7 @@ const Signup = (): React.ReactElement => {

return (
<div style={{ textAlign: "center" }}>
<h1>Signup</h1>
<h1>{capitalizeFirstLetter(role)} Signup</h1>
<form>
<div>
<input
Expand Down
Loading