forked from React-Group/interstellar_ai
I have immense pain in the left temple.
This commit is contained in:
parent
5adb7ff56e
commit
6435bfad8d
3 changed files with 96 additions and 78 deletions
|
@ -5,6 +5,7 @@ import {
|
|||
getSettings
|
||||
} from '../backend/database';
|
||||
import Settings from './settings/Settings'; // Import the Settings component
|
||||
import { importDatabase } from './settings/settingUtils';
|
||||
|
||||
const Login: React.FC = () => {
|
||||
// State to handle popup visibility
|
||||
|
@ -23,14 +24,14 @@ const Login: React.FC = () => {
|
|||
|
||||
// On component mount, check if there are credentials in localStorage
|
||||
useEffect(() => {
|
||||
let savedAccountName:string|null;
|
||||
let savedAccountEmail:string|null;
|
||||
let savedAccountPassword:string|null;
|
||||
let savedAccountName: string | null;
|
||||
let savedAccountEmail: string | null;
|
||||
let savedAccountPassword: string | null;
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
savedAccountName = localStorage.getItem('accountName');
|
||||
savedAccountEmail = localStorage.getItem('accountEmail');
|
||||
savedAccountPassword = localStorage.getItem('accountPassword');
|
||||
|
||||
|
||||
// If credentials are found in localStorage, log the user in
|
||||
if (savedAccountName && savedAccountEmail && savedAccountPassword) {
|
||||
setAccountName(savedAccountName);
|
||||
|
@ -40,6 +41,14 @@ const Login: React.FC = () => {
|
|||
if (savedAccountName !== null && savedAccountPassword !== null) {
|
||||
const success = await checkCredentials(savedAccountName, savedAccountPassword);
|
||||
setIsLoggedIn(success); // Automatically log in
|
||||
const useName = localStorage.getItem("accountName");
|
||||
const usePassword = localStorage.getItem("accountPassword");
|
||||
|
||||
if (useName && usePassword) {
|
||||
await importDatabase(useName, usePassword);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
check();
|
||||
|
@ -64,11 +73,19 @@ const Login: React.FC = () => {
|
|||
setIsLoggedIn(true); // Successful login
|
||||
const data = await getSettings(accountName, password)
|
||||
if (data) {
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
localStorage.setItem("dataFromServer", data)
|
||||
}
|
||||
}
|
||||
setShowLoginPopup(false); // Close the login popup
|
||||
const useName = localStorage.getItem("accountName");
|
||||
const usePassword = localStorage.getItem("accountPassword");
|
||||
|
||||
if (useName && usePassword) {
|
||||
await importDatabase(useName, usePassword);
|
||||
}
|
||||
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert('Incorrect credentials');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue