auth for partners

This commit is contained in:
kurpfish 2021-08-04 18:17:33 +03:00
parent 937a78b04f
commit 9a55d65db1
4 changed files with 42 additions and 16 deletions

View File

@ -16,18 +16,18 @@ const App = () => {
return (
<Router>
<Switch>
<Route path='/auth' exact>
{/* <AuthPageForPartners /> */}
<Route path='/authdev' exact>
<AuthPageForDevelopers />
</Route>
<Route path='/auth' exact>
<AuthPageForPartners />
</Route>
<ProtectedRoute path='/' exact component={HomePage} />
<ProtectedRoute path='/candidate/:id' component={CandidatePage} />
<ProtectedRoute path='/calendar' component={CalendarPage} />
<ProtectedRoute path='/form' component={FormPage} />
<ProtectedRoute path='/report' component={ReportPage} />
<Route>
<div>Page not found</div>
</Route>
<ProtectedRoute component={()=><div>Page not found</div>} />
</Switch>
</Router>
)

View File

@ -25,8 +25,6 @@ const AuthForDevelopers = () => {
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
console.log('i', isAuth)
if(isAuth) {
return <Redirect to='/' />
}

View File

@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import { auth } from '../../redux/outstaffingSlice';
import style from './AuthForPartners.module.css';
@ -12,9 +12,22 @@ import phone from '../../images/phone.png';
import telegram from '../../images/telegram.png';
import vector from '../../images/Vector_Smart_Object.png';
import vectorBlack from '../../images/Vector_Smart_Object_black.png';
import { fetchAuth } from '../../server/server'
import { useSelector } from 'react-redux'
import { selectAuth } from '../../redux/outstaffingSlice';
import { Redirect } from 'react-router-dom';
const AuthForPartners = () => {
const dispatch = useDispatch();
const dispatch = useDispatch()
const isAuth = useSelector(selectAuth)
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
if(isAuth) {
return <Redirect to='/' />
}
return (
<section className={style.partners}>
@ -34,12 +47,27 @@ const AuthForPartners = () => {
</div>
<form className={style.partners__form}>
<label htmlFor="login">Ваш логин:</label>
<input id="login" type="text" placeholder="Логин" />
<input id="login" type="text" placeholder="Логин"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<label htmlFor="password">Пароль:</label>
<input id="password" type="password" placeholder="Пароль" />
<input id="password" type="password" placeholder="Пароль"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<button className={style.form__btn} type="submit" onClick={() => dispatch(auth(true))}>
<button className={style.form__btn}
onClick={(e) => {
e.preventDefault();
fetchAuth({
username,
password,
dispatch: ()=> dispatch(auth(true))
})
}
}>
Войти
</button>
</form>

View File

@ -3,7 +3,7 @@ export const fetchProfile = async (link, index) => {
const response = await fetch(`${link}${index}`, {
headers: {
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`,
'Origin': `${baseURL}`,
'Origin': `${process.env.REACT_APP_BASE_URL}`,
}
})
let data = await response.json()
@ -17,7 +17,7 @@ export const fetchSkills = async (link) => {
const response = await fetch(link, {
headers: {
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`,
'Origin': `${baseURL}`,
'Origin': `${process.env.REACT_APP_BASE_URL}`,
}
})
let data = await response.json()
@ -31,7 +31,7 @@ export const fetchItemsForId = async (link, id) => {
const response = await fetch(`${link}${id}`, {
headers: {
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`,
'Origin': `${baseURL}`,
'Origin': `${process.env.REACT_APP_BASE_URL}`,
}
})
let data = await response.json()
@ -46,7 +46,7 @@ export const fetchForm = async (link, info) => {
method: 'POST',
headers: {
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`,
'Origin': `${baseURL}`,
'Origin': `${process.env.REACT_APP_BASE_URL}`,
'Content-Type': 'multipart/form-data'
},
body: info