Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/APIFunctions/Auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UserApiResponse, ApiResponse } from './ApiResponses';
import { BASE_API_URL } from '../Enums';
import Cookies from 'universal-cookie';


/**
Expand Down Expand Up @@ -88,18 +89,17 @@ export async function loginUser(email, password) {
}

/**
* Checks if the user is signed in by evaluating a jwt token in local storage.
* Checks if the user is signed in by evaluating a jwt token in cookies.
* @returns {UserApiResponse} Containing information for
* whether the user is signed or not
*/
export async function checkIfUserIsSignedIn() {
let status = new UserApiResponse();
const cookies = new Cookies();

const token = window.localStorage
? window.localStorage.getItem('jwtToken')
: '';
const token = cookies.get('jwtToken') ?? '';

// If there is not token in local storage,
// If there is not token in cookies,
// we cant do anything and return
if (!token) {
status.error = true;
Expand Down
3 changes: 3 additions & 0 deletions src/Components/Navbar/AdminNavbar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { useSCE } from '../context/SceContext';
import Cookies from 'universal-cookie';

export default function UserNavBar(props) {
const { user, setAuthenticated } = useSCE();
Expand All @@ -13,9 +14,11 @@ export default function UserNavBar(props) {
}
return className;
};
const cookies = new Cookies();

function handleLogout() {
setAuthenticated(false);
cookies.remove('jwtToken');
window.localStorage.removeItem('jwtToken');
Copy link
Collaborator

@joshua-demo joshua-demo Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove local storage line

window.location.reload();
}
Expand Down
3 changes: 3 additions & 0 deletions src/Components/Navbar/NavBarWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import React from 'react';
import UserNavbar from './UserNavbar';
import AdminNavbar from './AdminNavbar';
import { useSCE } from '../context/SceContext';
import Cookies from 'universal-cookie';

function NavBarWrapper({
enableAdminNavbar = false,
component: Component,
...appProps
}) {
const { user, setUser, setAuthenticated } = useSCE();
const cookies = new Cookies();

function handleLogout() {
setAuthenticated(false);
setUser({});
cookies.remove('jwtToken');
window.localStorage.removeItem('jwtToken');
Copy link
Collaborator

@joshua-demo joshua-demo Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove local storage line

window.location.reload();
}
Expand Down
7 changes: 5 additions & 2 deletions src/Pages/Login/Login.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import React, { useState } from 'react';
import { loginUser } from '../../APIFunctions/Auth';
import { useSCE } from '../../Components/context/SceContext';
import Cookies from 'universal-cookie';

export default function Login() {
const { setAuthenticated } = useSCE();
const queryParams = new URLSearchParams(window.location.search);
const [errorMsg, setErrorMsg] = useState('');
const cookies = new Cookies();

async function handleSubmit(e) {
e.preventDefault();
window.localStorage.removeItem('jwtToken'); // clean up local storage
const email = e.target.email.value;
const password = e.target.password.value;
setErrorMsg('');
const loginStatus = await loginUser(email, password);
if (!loginStatus.error) {
setAuthenticated(true);
window.localStorage.setItem('jwtToken', loginStatus.token);
cookies.set('jwtToken', loginStatus.token); // expire cookie after 1 week
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be more settings we add here, like https only if we are in prod and same site secure

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be more settings we add here, like https only if we are in prod and same site secure

if (queryParams.get('redirect')) {
window.location.href = queryParams.get('redirect');
return;
Expand Down Expand Up @@ -54,7 +57,7 @@ export default function Login() {
type="email"
placeholder="[email protected]"
required
autofocus="autofocus"
autoFocus="autofocus"
className="input input-bordered w-full"
/>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/Pages/Overview/Overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ConfirmationModal from
'../../Components/DecisionModal/ConfirmationModal.js';
const enums = require('../../Enums.js');
import { useSCE } from '../../Components/context/SceContext.js';
import Cookies from 'universal-cookie';

export default function Overview() {
const { user } = useSCE();
Expand All @@ -28,6 +29,7 @@ export default function Overview() {
// const [toggle, setToggle] = useState(false);
// const [currentQueryType, setCurrentQueryType] = useState('All');
// const queryTypes = ['All', 'Pending', 'Officer', 'Admin', 'Alumni'];
const cookies = new Cookies();

async function deleteUser(userToDel) {
const response = await deleteUserByID(
Expand All @@ -39,6 +41,7 @@ export default function Overview() {
}
if (userToDel._id === user._id) {
// logout
cookies.remove('jwtToken');
window.localStorage.removeItem('jwtToken');
window.location.reload();
return window.alert('Self-deprecation is an art');
Expand Down
3 changes: 3 additions & 0 deletions src/Pages/Profile/MemberView/DeleteAccountModal.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import { deleteUserByID } from '../../../APIFunctions/User';
import { useSCE } from '../../../Components/context/SceContext';
import Cookies from 'universal-cookie';

export default function DeleteAccountModal(props) {
const { bannerCallback = () => {} } = props;
const { user } = useSCE();
const cookies = new Cookies();

async function deleteAccount() {
const apiResponse = await deleteUserByID(
Expand All @@ -15,6 +17,7 @@ export default function DeleteAccountModal(props) {
if (!apiResponse.error) {
bannerCallback('Account Deleted', 'success');
setTimeout(() => {
cookies.remove('jwtToken');
window.localStorage.removeItem('jwtToken');
window.location.reload();
}, 2000);
Expand Down