extend the session manager and rename the bearer functions
This commit is contained in:
@@ -11,7 +11,8 @@ export const Auth: React.FC = () => {
|
|||||||
Session.setBearerToken(token);
|
Session.setBearerToken(token);
|
||||||
window.location.replace(`${baseUrl}/overview`);
|
window.location.replace(`${baseUrl}/overview`);
|
||||||
} else {
|
} else {
|
||||||
Session.reset();
|
Session.resetLastShownComponent();
|
||||||
|
Session.resetBearerToken();
|
||||||
window.location.replace(`${baseUrl}/`);
|
window.location.replace(`${baseUrl}/`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ export const Login: React.FC = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Auth.tokenIsValid().then((status) => {
|
Auth.tokenIsValid().then((status) => {
|
||||||
if (status !== BackendReturnStatus.Ok) {
|
if (status !== BackendReturnStatus.Ok) {
|
||||||
Session.reset();
|
Session.resetLastShownComponent();
|
||||||
|
Session.resetBearerToken();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} else {
|
} else {
|
||||||
navigate('/overview');
|
navigate('/overview');
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ export const Logout: React.FC = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Session.reset();
|
Session.resetLastShownComponent();
|
||||||
|
Session.resetBearerToken();
|
||||||
context.resetAuth();
|
context.resetAuth();
|
||||||
navigate('/');
|
navigate('/');
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export class Session {
|
export class Session {
|
||||||
static reset(): void {
|
static resetBearerToken(): void {
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,4 +18,16 @@ export class Session {
|
|||||||
static theme(): string | null {
|
static theme(): string | null {
|
||||||
return localStorage.getItem('theme');
|
return localStorage.getItem('theme');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static resetLastShownComponent(): void {
|
||||||
|
localStorage.removeItem('path');
|
||||||
|
}
|
||||||
|
|
||||||
|
static setLastShownComponent(path: string): void {
|
||||||
|
localStorage.setItem('path', path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static lastShownComponent(): string | null {
|
||||||
|
return localStorage.getItem('path');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user