Last change
on this file since efaa053 was 0f5aa27, checked in by darsov2 <62809499+darsov2@…>, 8 months ago |
ouath, mailing impl
|
-
Property mode
set to
100644
|
File size:
794 bytes
|
Rev | Line | |
---|
[0f5aa27] | 1 | import { useState } from "react";
|
---|
[e6c2521] | 2 | import axios from "../../../axios.js";
|
---|
[0f5aa27] | 3 | import {useAuth} from "../../Context/AuthContext"; // Assuming you have axios configured
|
---|
[e6c2521] | 4 |
|
---|
| 5 | const useLogin = () => {
|
---|
[0f5aa27] | 6 | const [loading, setLoading] = useState(false);
|
---|
| 7 | const [error, setError] = useState(null);
|
---|
[07f4e8b] | 8 | const Auth = useAuth();
|
---|
| 9 |
|
---|
[0f5aa27] | 10 | const handleLoginCallback = async () => {
|
---|
| 11 | setLoading(true);
|
---|
[e6c2521] | 12 |
|
---|
[0f5aa27] | 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 | }
|
---|
[e6c2521] | 26 | };
|
---|
| 27 |
|
---|
[0f5aa27] | 28 | return {
|
---|
| 29 | loading,
|
---|
| 30 | error,
|
---|
| 31 | handleLoginCallback,
|
---|
| 32 | };
|
---|
| 33 | };
|
---|
[e6c2521] | 34 |
|
---|
[0f5aa27] | 35 | export default useLogin;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.