Skip to content

Commit

Permalink
Expire session after timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinkyaraj-23 committed Feb 26, 2025
1 parent 6664491 commit 11f280e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
14 changes: 11 additions & 3 deletions apps/web/src/components/Onboarding/SetupPassword/SetupPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Text,
} from "@chakra-ui/react";
import { useMultiForm } from "@umami/components";
import { useIsPasswordSet } from "@umami/state";
import { useIsPasswordSet, useSessionTimeout } from "@umami/state";
import { defaultDerivationPathTemplate } from "@umami/tezos";
import { FormProvider } from "react-hook-form";

Expand Down Expand Up @@ -72,6 +72,7 @@ export const SetupPassword = ({ mode }: SetupPasswordProps) => {
const color = useColor();
const { onSubmit, isLoading } = useGetSetupPasswordSubmitHandler(mode);
const isPasswordSet = useIsPasswordSet();
const { setupSessionTimeout } = useSessionTimeout();

const form = useMultiForm<FormFields>({
mode: "all",
Expand All @@ -88,6 +89,13 @@ export const SetupPassword = ({ mode }: SetupPasswordProps) => {

const { title, subtitle, buttonLabel, icon } = getModeConfig(mode);

const handleSubmit = async (values: FormFields) => {
await onSubmit(values);
if (mode === "new_mnemonic") {
setupSessionTimeout();
}
};

return (
<ModalContent>
<ModalHeader>
Expand All @@ -106,7 +114,7 @@ export const SetupPassword = ({ mode }: SetupPasswordProps) => {
</Center>
</ModalHeader>
<FormProvider {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<form onSubmit={form.handleSubmit(handleSubmit)}>
<ModalBody>
<Flex flexDirection="column" gap="24px">
<PasswordInput
Expand Down Expand Up @@ -142,4 +150,4 @@ export const SetupPassword = ({ mode }: SetupPasswordProps) => {
</FormProvider>
</ModalContent>
);
};
};
1 change: 1 addition & 0 deletions packages/state/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from "./setAccountData";
export * from "./staking";
export * from "./tokens";
export * from "./WalletConnect";
export * from "./session";
20 changes: 20 additions & 0 deletions packages/state/src/hooks/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

const SESSION_TIMEOUT = 30 * 60 * 1000; // 30 minutes from login

export const useSessionTimeout = () => {

const setupSessionTimeout = () => {
try {
const timeoutId = window.setTimeout(() => {
sessionStorage.clear();
}, SESSION_TIMEOUT);

// Store timeout ID in case we need to clear it
sessionStorage.setItem("sessionTimeoutId", timeoutId.toString());
} catch (error) {
console.error("Failed to setup session timeout:", error);
}
};

return { setupSessionTimeout };
};

0 comments on commit 11f280e

Please sign in to comment.