aboutsummaryrefslogtreecommitdiff
path: root/packages/bank-ui/src/hooks/session.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/bank-ui/src/hooks/session.ts')
-rw-r--r--packages/bank-ui/src/hooks/session.ts12
1 files changed, 10 insertions, 2 deletions
diff --git a/packages/bank-ui/src/hooks/session.ts b/packages/bank-ui/src/hooks/session.ts
index 4520d0e4a..631c08bea 100644
--- a/packages/bank-ui/src/hooks/session.ts
+++ b/packages/bank-ui/src/hooks/session.ts
@@ -15,13 +15,16 @@
*/
import {
+ AbsoluteTime,
AccessToken,
Codec,
buildCodecForObject,
buildCodecForUnion,
+ codecForAbsoluteTime,
codecForBoolean,
codecForConstString,
codecForString,
+ codecOptionalDefault,
} from "@gnu-taler/taler-util";
import { buildStorageKey, useLocalStorage } from "@gnu-taler/web-util/browser";
import { mutate } from "swr";
@@ -32,16 +35,18 @@ import { mutate } from "swr";
*/
export type SessionState = LoggedIn | LoggedOut | Expired;
-interface LoggedIn {
+export interface LoggedIn {
status: "loggedIn";
isUserAdministrator: boolean;
username: string;
token: AccessToken;
+ expiration: AbsoluteTime;
}
interface Expired {
status: "expired";
isUserAdministrator: boolean;
username: string;
+ expiration: AbsoluteTime;
}
interface LoggedOut {
status: "loggedOut";
@@ -51,6 +56,7 @@ export const codecForSessionStateLoggedIn = (): Codec<LoggedIn> =>
buildCodecForObject<LoggedIn>()
.property("status", codecForConstString("loggedIn"))
.property("username", codecForString())
+ .property("expiration", codecOptionalDefault(codecForAbsoluteTime, AbsoluteTime.now()))
.property("token", codecForString() as Codec<AccessToken>)
.property("isUserAdministrator", codecForBoolean())
.build("SessionState.LoggedIn");
@@ -59,6 +65,7 @@ export const codecForSessionStateExpired = (): Codec<Expired> =>
buildCodecForObject<Expired>()
.property("status", codecForConstString("expired"))
.property("username", codecForString())
+ .property("expiration", codecOptionalDefault(codecForAbsoluteTime, AbsoluteTime.now()))
.property("isUserAdministrator", codecForBoolean())
.build("SessionState.Expired");
@@ -83,7 +90,7 @@ export interface SessionStateHandler {
state: SessionState;
logOut(): void;
expired(): void;
- logIn(info: { username: string; token: AccessToken }): void;
+ logIn(info: { username: string; token: AccessToken, expiration: AbsoluteTime }): void;
}
const SESSION_STATE_KEY = buildStorageKey(
@@ -112,6 +119,7 @@ export function useSessionState(): SessionStateHandler {
const nextState: SessionState = {
status: "expired",
username: state.username,
+ expiration: state.expiration,
isUserAdministrator: state.username === "admin",
};
update(nextState);