fix
This commit is contained in:
parent
f8d69be0df
commit
952bfb6327
|
|
@ -1,5 +1,7 @@
|
|||
import { FC, useEffect } from "react";
|
||||
import { loadSession } from "./utils/load";
|
||||
import { useLocal } from "lib/utils/use-local";
|
||||
import { FieldLoading } from "../../..";
|
||||
|
||||
const w = window as unknown as {
|
||||
user: any;
|
||||
|
|
@ -7,21 +9,35 @@ const w = window as unknown as {
|
|||
};
|
||||
|
||||
export type LGProps = {
|
||||
salt: string;
|
||||
url_home: Array<Record<string, string>>;
|
||||
url_home: Record<string, string>;
|
||||
body: any;
|
||||
};
|
||||
|
||||
export const Login: FC<LGProps> = (props) => {
|
||||
w.prasi_home = props.url_home[0];
|
||||
useEffect(() => {
|
||||
try {
|
||||
const local = useLocal({ loading: true }, () => {
|
||||
loadSession();
|
||||
setTimeout(() => {
|
||||
if (w.user) {
|
||||
const home = w.prasi_home[w.user.m_role.name];
|
||||
const home = props.url_home[w.user.role];
|
||||
if (home) {
|
||||
navigate(home);
|
||||
return;
|
||||
}
|
||||
} catch (e: any) {}
|
||||
}, []);
|
||||
}
|
||||
local.loading = false;
|
||||
local.render();
|
||||
}, 500);
|
||||
});
|
||||
|
||||
if (local.loading)
|
||||
return (
|
||||
<div
|
||||
className={css`
|
||||
padding: 10px;
|
||||
`}
|
||||
>
|
||||
<FieldLoading />
|
||||
</div>
|
||||
);
|
||||
return <>{props.body}</>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ export type UserSession = {
|
|||
expired: Date; // second
|
||||
};
|
||||
export const registerSession = (session: RG) => {
|
||||
if (session.role) {
|
||||
session.data.role = session.role;
|
||||
}
|
||||
const data = {
|
||||
data: session.data,
|
||||
expired: session.expired ? day().add(session.expired, "seconds") : null,
|
||||
|
|
@ -25,4 +28,5 @@ export const registerSession = (session: RG) => {
|
|||
|
||||
localStorage.setItem("user" + id_site, JSON.stringify(data));
|
||||
w.user = session.data;
|
||||
w.user.role = session.role;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue