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

[FAB-22] User auth #12

Merged
merged 9 commits into from
Aug 16, 2021
Merged

[FAB-22] User auth #12

merged 9 commits into from
Aug 16, 2021

Conversation

daystram
Copy link
Contributor

No description provided.

fableous-fe/src/Api.tsx Outdated Show resolved Hide resolved
fableous-fe/src/containers/LoginPage.tsx Outdated Show resolved Hide resolved
fableous-fe/src/containers/RegisterPage.tsx Outdated Show resolved Hide resolved
@daystram daystram marked this pull request as draft August 16, 2021 01:49
@wahyuadt wahyuadt marked this pull request as ready for review August 16, 2021 03:08
@daystram daystram requested a review from wahyuadt August 16, 2021 03:29
@daystram daystram merged commit a254f08 into master Aug 16, 2021
@nicolauscg
Copy link
Member

nicolauscg commented Aug 16, 2021

I tried running on localhost, do we want to implement the following?

  • redirect to homepage after successful login
  • if login page is visited and user is already logged in, redirect to homepage too
  • add login and register button to navbar only if user not logged in
  • logout button on navbar if user logged in, which just clears token in localstorage

these could be put into jira task and implemented later in another branch

@nicolauscg
Copy link
Member

I also tried to do a post req in homepage and did not find the token in header of request, is this in scope?

  const testPost = () => {
    axios.post("/api", {});
  };

  useEffect(() => {
    testPost();
  }, []);

mayba need interceptor along the lines of below? (copied from impensa)

axios.interceptors.request.use(
  config => {
    if (isLoggedIn()) {
      const userObject = getUserObject();
      config.headers.Authorization = `Bearer ${userObject.token}`;
    } else {
      clearUserObject();
    }

    return config;
  },
  error => Promise.reject(error)
); 


const auth = {
saveToken: (token: AxiosResponse<any>) => {
localStorage.setItem(TOKEN_KEY, token.headers.authorization);
Copy link
Member

Choose a reason for hiding this comment

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

one more thing @wahyuadt , in this file u save the token "Bearer abcdef..." as is, that exact format (with Bearer) is needed for rest API requests, but for websocket requests, the only thing needed it the token part (WITHOUT Bearer), so I think its better to save only the "abcdef..." part, and in interceptor, append it to "Bearere "

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