Autologin via ?hash=xxx parameter in url

This commit is contained in:
Dario Guarascio 2021-10-09 11:47:20 +02:00
parent 2575cbfc11
commit 6bd01aaa45
8 changed files with 64 additions and 4 deletions

View file

@ -27,11 +27,25 @@ const validate = ({ username, password }) => {
return errors;
};
export default function LoginForm() {
export default function LoginForm({ hash = null }) {
const post = usePost();
const router = useRouter();
const [message, setMessage] = useState();
const handleAutologin = async ({ hash }) => {
const autologin = await post('/api/auth/hash', {
hash,
});
if (autologin.ok) {
return router.push('/');
}
};
if (hash) {
handleAutologin({ hash });
}
const handleSubmit = async ({ username, password }) => {
const { ok, status, data } = await post('/api/auth/login', {
username,