Last change
on this file was 0f5aa27, checked in by darsov2 <62809499+darsov2@…>, 8 months ago |
ouath, mailing impl
|
-
Property mode
set to
100644
|
File size:
794 bytes
|
Line | |
---|
1 | import { useState } from "react";
|
---|
2 | import axios from "../../../axios.js";
|
---|
3 | import {useAuth} from "../../Context/AuthContext"; // Assuming you have axios configured
|
---|
4 |
|
---|
5 | const useLogin = () => {
|
---|
6 | const [loading, setLoading] = useState(false);
|
---|
7 | const [error, setError] = useState(null);
|
---|
8 | const Auth = useAuth();
|
---|
9 |
|
---|
10 | const handleLoginCallback = async () => {
|
---|
11 | setLoading(true);
|
---|
12 |
|
---|
13 | try {
|
---|
14 | const response = await axios.get("http://localhost:8080/principal");
|
---|
15 |
|
---|
16 | // Extract the needed attributes from the response
|
---|
17 | const { id, role, username } = response.data;
|
---|
18 |
|
---|
19 | Auth.userLogin({userId: id, username: username, role: role})
|
---|
20 |
|
---|
21 | } catch (err) {
|
---|
22 | setError(err.message);
|
---|
23 | } finally {
|
---|
24 | setLoading(false);
|
---|
25 | }
|
---|
26 | };
|
---|
27 |
|
---|
28 | return {
|
---|
29 | loading,
|
---|
30 | error,
|
---|
31 | handleLoginCallback,
|
---|
32 | };
|
---|
33 | };
|
---|
34 |
|
---|
35 | export default useLogin;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.