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

Add state for current user #665

Merged
merged 2 commits into from
Aug 15, 2023
Merged

Add state for current user #665

merged 2 commits into from
Aug 15, 2023

Conversation

acrantel
Copy link
Member

finally got around to pulling this into a separate pr from the login / register pages...

this pr adds a CurrentUserContext to hold the state of the current user. It also adds a PrivateRoute component which redirects people to the login page if they are not logged upon load.

@@ -0,0 +1,12 @@
import Cookies from "js-cookie";
Copy link
Member Author

Choose a reason for hiding this comment

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

this is a util file that will be used for the login / register pages

@n8kim1
Copy link
Contributor

n8kim1 commented Aug 14, 2023

context omg amaze

Copy link
Contributor

@lowtorola lowtorola left a comment

Choose a reason for hiding this comment

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

Looks great! Left some comments regarding interfacing with existing api/auth functionality and regarding changes vs #664 🚀

import React, { useState, useEffect } from "react";
import { type UserPrivate } from "../utils/types";
import { AuthStateEnum, type AuthState, CurrentUserContext } from "../contexts/CurrentUserContext";
import { Api } from "../utils/api";
Copy link
Contributor

@lowtorola lowtorola Aug 14, 2023

Choose a reason for hiding this comment

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

After #664 is merged, this will need to change to import * as Api 👍

navigate("/login");
return null;
} else {
return <p>loading</p>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a more populated loading screen here (e.g. using Spinner)? Not necessary though, we can just go back and add one later if we need...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, i'll change this to a centered Spinner in the page

Copy link
Contributor

@lowtorola lowtorola left a comment

Choose a reason for hiding this comment

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

LGTM! 🥳

@acrantel acrantel merged commit 092bef2 into frontend2 Aug 15, 2023
3 checks passed
@acrantel acrantel deleted the current-user branch August 15, 2023 23:06
acrantel added a commit that referenced this pull request Aug 15, 2023
acrantel added a commit that referenced this pull request Aug 15, 2023
acrantel added a commit that referenced this pull request Oct 3, 2023
acrantel added a commit that referenced this pull request Feb 8, 2024
acrantel added a commit that referenced this pull request Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants