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

Added author_id to login response and methods to store and retrieve a… #61

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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("author_id");
};
4 changes: 3 additions & 1 deletion server/socialdistribution/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def post(self, request):
if success:
# create token
token, created = Token.objects.get_or_create(user=user)
data = {"token": token.key}
matching_author = Author.objects.get(user=user)

data = {"token": token.key, "author_id": matching_author.id}
return Response(data, status=status.HTTP_201_CREATED)
# on wrong password
else:
Expand Down