1
1
import React , { useState } from 'react' ;
2
+ import { useNavigate } from 'react-router-dom' ;
2
3
// @material -ui/core components
3
4
import FormControl from '@material-ui/core/FormControl' ;
4
5
import InputLabel from '@material-ui/core/InputLabel' ;
@@ -12,10 +13,10 @@ import CardHeader from '../../components/Card/CardHeader';
12
13
import CardBody from '../../components/Card/CardBody' ;
13
14
import CardFooter from '../../components/Card/CardFooter' ;
14
15
import axios from 'axios' ;
15
- import { Navigate } from 'react-router-dom' ;
16
16
import logo from '../../assets/img/git-proxy.png' ;
17
17
import { Badge , CircularProgress , Snackbar } from '@material-ui/core' ;
18
18
import { getCookie } from '../../utils' ;
19
+ import { useAuth } from '../../auth/AuthProvider' ;
19
20
20
21
const loginUrl = `${ import . meta. env . VITE_API_URI } /api/auth/login` ;
21
22
@@ -27,6 +28,9 @@ export default function UserProfile() {
27
28
const [ gitAccountError , setGitAccountError ] = useState ( false ) ;
28
29
const [ isLoading , setIsLoading ] = useState ( false ) ;
29
30
31
+ const navigate = useNavigate ( ) ;
32
+ const { refreshUser } = useAuth ( ) ;
33
+
30
34
function validateForm ( ) {
31
35
return (
32
36
username . length > 0 && username . length < 100 && password . length > 0 && password . length < 200
@@ -57,8 +61,8 @@ export default function UserProfile() {
57
61
. then ( function ( ) {
58
62
window . sessionStorage . setItem ( 'git.proxy.login' , 'success' ) ;
59
63
setMessage ( 'Success!' ) ;
60
- setSuccess ( true ) ;
61
64
setIsLoading ( false ) ;
65
+ refreshUser ( ) . then ( ( ) => navigate ( '/dashboard/repo' ) ) ;
62
66
} )
63
67
. catch ( function ( error ) {
64
68
if ( error . response . status === 307 ) {
@@ -75,13 +79,6 @@ export default function UserProfile() {
75
79
event . preventDefault ( ) ;
76
80
}
77
81
78
- if ( gitAccountError ) {
79
- return < Navigate to = { { pathname : '/dashboard/profile' } } /> ;
80
- }
81
- if ( success ) {
82
- return < Navigate to = { { pathname : '/dashboard/profile' , state : { authed : true } } } /> ;
83
- }
84
-
85
82
return (
86
83
< form onSubmit = { handleSubmit } >
87
84
< Snackbar
0 commit comments