-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Prrromanssss/frontend_auth
make authorization on frontend side: login/register forms, authorization header for jwt token
- Loading branch information
Showing
19 changed files
with
213 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.container { | ||
border-radius: 20px; | ||
padding: 20px; | ||
display: flex; | ||
align-items: center; | ||
flex-direction: column; | ||
border: 1px solid black; | ||
width: 100%; | ||
max-width: 300px; | ||
gap: 10px; | ||
|
||
} | ||
|
||
.input { | ||
padding: 10px; | ||
border-radius: 10px; | ||
border: 1px solid black; | ||
width: 100%; | ||
} | ||
|
||
.button { | ||
padding: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import styles from "./LoginForm.module.css"; | ||
import { FormProps } from "src/ts/interfaces"; | ||
|
||
export const LoginForm = ({ variant, handler, data, setData }: FormProps) => { | ||
return ( | ||
<div className={styles.container}> | ||
<input | ||
name="email" | ||
onChange={(e) => setData({ ...data, email: e.target.value })} | ||
value={data.email} | ||
className={styles.input} | ||
placeholder="Email..." | ||
/> | ||
<input | ||
name="password" | ||
type="password" | ||
onChange={(e) => setData({ ...data, password: e.target.value })} | ||
value={data.password} | ||
className={styles.input} | ||
placeholder="Password..." | ||
/> | ||
<button | ||
className={styles.button} | ||
disabled={!data.email.length || !data.password.length} | ||
onClick={handler} | ||
> | ||
{variant === "login" ? "Войти" : "Регистрация"} | ||
</button> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.tsx' | ||
import { ToastContainer } from 'react-toastify'; | ||
import 'react-toastify/dist/ReactToastify.css'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
<React.StrictMode> | ||
<> | ||
<App /> | ||
<ToastContainer /> | ||
</React.StrictMode>, | ||
</>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.container { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
} | ||
|
||
.containerBtn { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
gap: 5px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.activeElement { | ||
cursor: pointer; | ||
padding: 5px 10px; | ||
border-radius: 10px; | ||
border: 1px solid black; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { LoginForm } from "src/components/LoginForm/LoginForm"; | ||
import styles from "./LoginPage.module.css"; | ||
import { useState } from "react"; | ||
import { FormVariant } from "src/ts/types"; | ||
import { login, registration } from "src/services/api"; | ||
import { toast } from "react-toastify"; | ||
|
||
export const LoginPage = () => { | ||
const [variant, setVariant] = useState<FormVariant>("login"); | ||
const [data, setData] = useState({ | ||
email: "", | ||
password: "", | ||
}); | ||
|
||
const handler = () => { | ||
if (variant === "login") { | ||
login(data).then(() => { | ||
setData({ email: "", password: "" }) | ||
toast.success("Успешно!"); | ||
}); | ||
} else { | ||
registration(data).then(() => { | ||
toast.success("Успешно!"); | ||
setVariant("login"); | ||
}) | ||
.catch((err) => { | ||
toast.error(err.response.data.error); | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<div className={styles.containerBtn}> | ||
<div | ||
onClick={() => { | ||
setData({ email: "", password: "" }); | ||
setVariant("login"); | ||
}} | ||
className={styles.activeElement} | ||
style={{ | ||
background: variant === "login" ? "blue" : "white", | ||
color: variant === "login" ? "white" : "black", | ||
}} | ||
> | ||
Вход | ||
</div> | ||
<div>/</div> | ||
<div | ||
onClick={() => { | ||
setData({ email: "", password: "" }); | ||
setVariant("reg"); | ||
}} | ||
className={styles.activeElement} | ||
style={{ | ||
background: variant === "reg" ? "blue" : "white", | ||
color: variant === "reg" ? "white" : "black", | ||
}} | ||
> | ||
Регистрация | ||
</div> | ||
</div> | ||
<LoginForm | ||
variant={variant} | ||
handler={handler} | ||
data={data} | ||
setData={setData} | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.