CommunityOfCoders / COCWebsite

The official website of Community Of Coders, VJTI.

Home Page:https://www.communityofcoders.in

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default option shown to a new user is "Logout"

akshatshah21 opened this issue · comments

I have observed that for a logged out user, the default option shown for auth is "Logout", even though the user has no auth token. The reason is the line 14 shown below. It checks localStorage.get('token') for an empty string. It should instead check if it's null

const initialState = {
token: localStorage.getItem("token"),
isAuthenticated: localStorage.getItem("token") !== "",
isLoading: null,
userID: localStorage.getItem("userID") ? localStorage.getItem("userID") : "",
username: localStorage.getItem("username") ? localStorage.getItem("username") : ""
};

This might be the same issue as the one mentioned at the end of this comment

Thanks for this. Seems like a quick fix should be !!localStorage.getItem("token"), to ensure we have truth values only. Do you mind putting up a PR for this?