Přesun autentizace na server

This commit is contained in:
2023-06-28 07:24:26 +02:00
parent 47fbe4173d
commit e81c7d09a3
15 changed files with 297 additions and 134 deletions

View File

@@ -1,6 +1,7 @@
import React, { useCallback, useRef } from 'react';
import { Button } from 'react-bootstrap';
import { useAuth } from './context/auth';
import { login } from './Api';
import './Login.css';
/**
@@ -10,10 +11,14 @@ export default function Login() {
const auth = useAuth();
const loginRef = useRef<HTMLInputElement>(null);
const doLogin = useCallback(() => {
const doLogin = useCallback(async () => {
const length = loginRef?.current?.value && loginRef?.current?.value.length && loginRef.current.value.replace(/\s/g, '').length
if (length) {
auth?.setLogin(loginRef.current.value);
// TODO odchytávat cokoliv mimo 200
const token = await login(loginRef.current.value);
if (token) {
auth?.setToken(token);
}
}
}, [auth]);