Last change
on this file since 5528b99 was 5528b99, checked in by darsov2 <62809499+darsov2@…>, 10 months ago |
revert
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[e6c2521] | 1 | import React from "react";
|
---|
| 2 |
|
---|
| 3 | import axios from "../../../axios.js";
|
---|
| 4 | import { Navigate, useAsyncValue, useNavigate } from "react-router-dom";
|
---|
| 5 | import LoginForm from "../../Login/LoginForm.js";
|
---|
| 6 |
|
---|
| 7 | const useLogin = () => {
|
---|
| 8 |
|
---|
| 9 | const navigator = useNavigate()
|
---|
| 10 | //const history = useNavigate();
|
---|
| 11 | const login = async (loginData) => {
|
---|
| 12 | console.log({loginData})
|
---|
| 13 | console.log(loginData)
|
---|
| 14 | await axios
|
---|
| 15 | .post(`/api/login`, {
|
---|
| 16 | username: loginData.email,
|
---|
| 17 | password: loginData.password
|
---|
| 18 | }, {
|
---|
| 19 | headers: {
|
---|
| 20 | "Content-Type": "application/x-www-form-urlencoded"
|
---|
| 21 | }
|
---|
| 22 | })
|
---|
| 23 | .then((res) => {
|
---|
| 24 | const sessionId = res.data.auth.details.sessionId;
|
---|
| 25 | const userId = res.data.auth.principal.userID;
|
---|
[5528b99] | 26 |
|
---|
[e6c2521] | 27 | localStorage.setItem("sessionId", sessionId);
|
---|
| 28 | localStorage.setItem("userId", userId);
|
---|
| 29 | if(sessionId === null)
|
---|
| 30 | {
|
---|
| 31 | }
|
---|
| 32 | navigator("/home")
|
---|
| 33 | })
|
---|
| 34 | .catch((err) => {
|
---|
| 35 | console.log(err);
|
---|
| 36 | })
|
---|
| 37 | .finally(() => {
|
---|
| 38 | });
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | return {
|
---|
| 42 | login
|
---|
| 43 | };
|
---|
| 44 |
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | export default useLogin; |
---|
Note:
See
TracBrowser
for help on using the repository browser.