import { Component, createEffect, createSignal } from 'solid-js'; import RestClient from '../api/RestClient'; import { setStore, store, User } from '../App'; import Button from '../ui/Button'; type LoginRequest = { login: string; password: string; }; const [loggedInUser, setLoggedInUser] = createSignal(); export { loggedInUser }; const Login: Component = () => { const [loginRequest, setLoginRequest] = createSignal({ login: '', password: '', }); const [login, setLogin] = createSignal(''); const [password, setPassword] = createSignal(''); // Populate the current user outside the JSX (we need createEffect for this!) createEffect(async () => { if (loginRequest().login.trim() === '' || loginRequest().password.trim() === '') { return; } const user = (await RestClient.POST( '/login', JSON.stringify(loginRequest()) )) as User; if (user.id === undefined) { console.log(user); return; } setStore({ ...store, user, }); window.location.href = '/'; }); return (
setLogin(e.currentTarget.value)} value={login()} />
setPassword(e.currentTarget.value)} value={password()} />

Want to track your todo{"'"}s?{' '} Register

); }; export default Login;