From 32c538a68062c4a6a0293129d21a6fc619b69f32 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 15 Nov 2020 05:04:08 +0300
Subject: feat: create user if it does not exist

---
 src/containers/BsuFantomSection/LoginForm.tsx | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

(limited to 'src/containers/BsuFantomSection/LoginForm.tsx')

diff --git a/src/containers/BsuFantomSection/LoginForm.tsx b/src/containers/BsuFantomSection/LoginForm.tsx
index 3204a64..69cba90 100644
--- a/src/containers/BsuFantomSection/LoginForm.tsx
+++ b/src/containers/BsuFantomSection/LoginForm.tsx
@@ -1,6 +1,7 @@
 import React, { useState } from 'react';
 import { TextField, Button, Grid } from '@material-ui/core';
 import { useAuth } from '../../hooks/useAuth';
+import { post } from '../../requests';
 
 
 const LoginForm: React.FC = () => {
@@ -16,7 +17,10 @@ const LoginForm: React.FC = () => {
     setPassword(event.target.value);
   };
 
-  const handleSubmit = () => login(username, password);
+  const handleSubmit = () => login(username, password)
+    .then(success => success || post('/users', { username, password })
+      .then(() => login(username, password))
+    );
 
   return (
       <Grid container direction="column" spacing={2}>
-- 
cgit v1.2.3

