Persisting admin credentials in session storage

This commit is contained in:
Eric van der Vlist 2023-02-26 17:16:42 +01:00
parent 81ff27fd0c
commit 57e0b32082
1 changed files with 15 additions and 1 deletions

View File

@ -1,7 +1,13 @@
import { createForm } from '@felte/solid'; import { createForm } from '@felte/solid';
import reporter from '@felte/reporter-tippy'; import reporter from '@felte/reporter-tippy';
import { Button, Dialog, TextField } from '@kobalte/core'; 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'; import 'tippy.js/dist/tippy.css';
interface CredentialsType { interface CredentialsType {
@ -17,6 +23,13 @@ export { adminCredentials };
interface Props {} interface Props {}
const Credentials: Component<Props> = (props) => { const Credentials: Component<Props> = (props) => {
createEffect(() => {
const storedAdminCredentials = sessionStorage.getItem('adminCredentials');
if (storedAdminCredentials) {
setAdminCredentials(JSON.parse(storedAdminCredentials));
}
});
const validationHandler = async (values: any) => { const validationHandler = async (values: any) => {
const { database, username, password } = values; const { database, username, password } = values;
let errors: any = {}; let errors: any = {};
@ -84,6 +97,7 @@ const Credentials: Component<Props> = (props) => {
context, context,
}); });
setAdminCredentials(values); setAdminCredentials(values);
sessionStorage.setItem('adminCredentials', JSON.stringify(values));
}; };
let { form, data } = createForm({ let { form, data } = createForm({