Skip to content

Commit

Permalink
Added author_id to login response and methods to store and retrieve a…
Browse files Browse the repository at this point in the history
…uthor_id from localStorage
  • Loading branch information
nluu175 committed Oct 24, 2023
1 parent 8792816 commit 16297ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion client/src/components/authentication/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { toast } from "react-toastify";
import { useNavigate } from "react-router-dom";
import axios from "axios";

import { storeToken } from "../../utils/localStorageUtils";
import { storeAuthorId, storeToken } from "../../utils/localStorageUtils";

const Login = () => {
const navigate = useNavigate();
Expand All @@ -35,6 +35,7 @@ const Login = () => {
headers: { "Content-Type": "multipart/form-data" },
})
.then((response: any) => {
storeAuthorId(response.data.author_id);
storeToken(response.data.token);

toast.success("You are now logged in");
Expand Down
8 changes: 8 additions & 0 deletions client/src/utils/localStorageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ export const storeToken = (token: string) => {
export const getToken = () => {
return localStorage.getItem("authToken");
};

export const storeAuthorId = (authorId: string) => {
localStorage.setItem("author_id", authorId);
};

export const getAuthorId = () => {
return localStorage.getItem("authToken");
};

0 comments on commit 16297ac

Please sign in to comment.