Add username to local storage and retrieve it in YourProjectsPage
This commit is contained in:
parent
3c8b7f9da2
commit
68b25350ef
2 changed files with 4 additions and 3 deletions
|
@ -25,6 +25,7 @@ function LoginCheck(props: {
|
||||||
if (response.data !== undefined) {
|
if (response.data !== undefined) {
|
||||||
const token = response.data;
|
const token = response.data;
|
||||||
localStorage.setItem("accessToken", token);
|
localStorage.setItem("accessToken", token);
|
||||||
|
localStorage.setItem("username", props.username);
|
||||||
//TODO: change so that it checks for user type (admin, user, pm) instead
|
//TODO: change so that it checks for user type (admin, user, pm) instead
|
||||||
if (token !== "" && props.username === "admin") {
|
if (token !== "" && props.username === "admin") {
|
||||||
props.setAuthority((prevAuth) => {
|
props.setAuthority((prevAuth) => {
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { Project } from "../Types/goTypes";
|
import { Project } from "../Types/goTypes";
|
||||||
import { api } from "../API/API";
|
import { api } from "../API/API";
|
||||||
import { Link, useLocation } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import BasicWindow from "../Components/BasicWindow";
|
import BasicWindow from "../Components/BasicWindow";
|
||||||
|
|
||||||
function UserProjectPage(): JSX.Element {
|
function UserProjectPage(): JSX.Element {
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
|
|
||||||
const getProjects = async (): Promise<void> => {
|
const getProjects = async (): Promise<void> => {
|
||||||
const username = "user"; // replace with actual username
|
const username = localStorage.getItem("username") ?? ""; // replace with actual username
|
||||||
const token = "your_token"; // replace with actual token
|
const token = localStorage.getItem("accessToken") ?? ""; // replace with actual token
|
||||||
const response = await api.getUserProjects(username, token);
|
const response = await api.getUserProjects(username, token);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setProjects(response.data ?? []);
|
setProjects(response.data ?? []);
|
||||||
|
|
Loading…
Reference in a new issue