Last change
on this file since bc20307 was bc20307, checked in by Tasevski2 <39170279+Tasevski2@…>, 2 years ago |
Push before video
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[bc20307] | 1 | import { useContext } from 'react';
|
---|
| 2 | import axios from 'axios';
|
---|
| 3 | import jwt from 'jwt-decode';
|
---|
| 4 | import { AccessoriesContext } from '../context/AccessoriesContext';
|
---|
| 5 | import { UserContext } from '../context/UserContext';
|
---|
| 6 | import useLogin from './useLogin';
|
---|
| 7 |
|
---|
| 8 | const useLoginGuest = () => {
|
---|
| 9 | const { setAlert, setIsBackdropLoaderOpen } =
|
---|
| 10 | useContext(AccessoriesContext);
|
---|
| 11 | const { loginUser } = useLogin();
|
---|
| 12 | const loginGuest = async ({ credentials }) => {
|
---|
| 13 | setIsBackdropLoaderOpen(true);
|
---|
| 14 | await axios
|
---|
| 15 | .post(`/guest`, credentials)
|
---|
| 16 | .then(async ({ data: guest }) => {
|
---|
| 17 | await loginUser({
|
---|
| 18 | email: guest.email,
|
---|
| 19 | password: guest.password,
|
---|
| 20 | });
|
---|
| 21 | })
|
---|
| 22 | .catch((err) => {
|
---|
| 23 | console.log(err);
|
---|
| 24 | setAlert({
|
---|
| 25 | type: 'error',
|
---|
| 26 | msg: 'Проблеми со серверот!', // TODO change msg to err.message
|
---|
| 27 | });
|
---|
| 28 | })
|
---|
| 29 | .finally(() => {
|
---|
| 30 | setIsBackdropLoaderOpen(false);
|
---|
| 31 | });
|
---|
| 32 | };
|
---|
| 33 | return {
|
---|
| 34 | loginGuest,
|
---|
| 35 | };
|
---|
| 36 | };
|
---|
| 37 |
|
---|
| 38 | export default useLoginGuest;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.