Commit 79842b1d authored by Daniel Puchala's avatar Daniel Puchala
Browse files

feat: changed saving jwt token from local to session storage

parent c95e35cd
import instance from '../models/axios';
import jwtDecode from 'jwt-decode';
export const login = async (name: string, password: string) => {
try {
const response = await instance.post('login', {
name, password
});
localStorage.setItem('user', JSON.stringify(jwtDecode(response.data)));
sessionStorage.setItem('user', JSON.stringify(jwtDecode(response.data)));
return response;
} catch (error) {
return error;
......@@ -15,10 +14,10 @@ export const login = async (name: string, password: string) => {
}
export const logout = () => {
localStorage.removeItem('user');
sessionStorage.removeItem('user');
}
export const getUser = () => {
const user = localStorage.getItem('user');
const user = sessionStorage.getItem('user');
return user ? JSON.parse(user) : null;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment