changed project struture.
Also addded a functional JWT token service. Also added user react frontend
This commit is contained in:
12
frontend_admin/src/utils/functions.ts
Normal file
12
frontend_admin/src/utils/functions.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
export const greeting = () => {
|
||||
return Cookies.get("name") ?? "Login";
|
||||
};
|
||||
|
||||
export const logout = () => {
|
||||
Cookies.remove("name");
|
||||
Cookies.remove("token");
|
||||
localStorage.removeItem("users");
|
||||
window.location.reload();
|
||||
};
|
29
frontend_admin/src/utils/useUsers.ts
Normal file
29
frontend_admin/src/utils/useUsers.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
username: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
email: string;
|
||||
password: string;
|
||||
created: string;
|
||||
}
|
||||
|
||||
export function useUsers(): User[] {
|
||||
const [users, setUsers] = useState<User[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const data = localStorage.getItem("users");
|
||||
if (data) {
|
||||
try {
|
||||
const parsed = JSON.parse(data);
|
||||
setUsers(parsed.result || []);
|
||||
} catch {
|
||||
setUsers([]);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
return users;
|
||||
}
|
Reference in New Issue
Block a user