From 57e0b32082e7a82271dc1d35e3077372b4891871 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Sun, 26 Feb 2023 17:16:42 +0100 Subject: [PATCH] Persisting admin credentials in session storage --- src/components/credentials/Credentials.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/credentials/Credentials.tsx b/src/components/credentials/Credentials.tsx index c6f25f4..737fb44 100644 --- a/src/components/credentials/Credentials.tsx +++ b/src/components/credentials/Credentials.tsx @@ -1,7 +1,13 @@ import { createForm } from '@felte/solid'; import reporter from '@felte/reporter-tippy'; import { Button, Dialog, TextField } from '@kobalte/core'; -import { Component, createSignal, JSXElement, Show } from 'solid-js'; +import { + Component, + createEffect, + createSignal, + JSXElement, + Show, +} from 'solid-js'; import 'tippy.js/dist/tippy.css'; interface CredentialsType { @@ -17,6 +23,13 @@ export { adminCredentials }; interface Props {} const Credentials: Component = (props) => { + createEffect(() => { + const storedAdminCredentials = sessionStorage.getItem('adminCredentials'); + if (storedAdminCredentials) { + setAdminCredentials(JSON.parse(storedAdminCredentials)); + } + }); + const validationHandler = async (values: any) => { const { database, username, password } = values; let errors: any = {}; @@ -84,6 +97,7 @@ const Credentials: Component = (props) => { context, }); setAdminCredentials(values); + sessionStorage.setItem('adminCredentials', JSON.stringify(values)); }; let { form, data } = createForm({