Skip to content

Commit 3702acd

Browse files
committed
fix(auth): fix redirect on local login
1 parent e7ec1f0 commit 3702acd

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/ui/views/Login/Login.jsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState } from 'react';
2+
import { useNavigate } from 'react-router-dom';
23
// @material-ui/core components
34
import FormControl from '@material-ui/core/FormControl';
45
import InputLabel from '@material-ui/core/InputLabel';
@@ -12,10 +13,10 @@ import CardHeader from '../../components/Card/CardHeader';
1213
import CardBody from '../../components/Card/CardBody';
1314
import CardFooter from '../../components/Card/CardFooter';
1415
import axios from 'axios';
15-
import { Navigate } from 'react-router-dom';
1616
import logo from '../../assets/img/git-proxy.png';
1717
import { Badge, CircularProgress, Snackbar } from '@material-ui/core';
1818
import { getCookie } from '../../utils';
19+
import { useAuth } from '../../auth/AuthProvider';
1920

2021
const loginUrl = `${import.meta.env.VITE_API_URI}/api/auth/login`;
2122

@@ -27,6 +28,9 @@ export default function UserProfile() {
2728
const [gitAccountError, setGitAccountError] = useState(false);
2829
const [isLoading, setIsLoading] = useState(false);
2930

31+
const navigate = useNavigate();
32+
const { refreshUser } = useAuth();
33+
3034
function validateForm() {
3135
return (
3236
username.length > 0 && username.length < 100 && password.length > 0 && password.length < 200
@@ -57,8 +61,8 @@ export default function UserProfile() {
5761
.then(function () {
5862
window.sessionStorage.setItem('git.proxy.login', 'success');
5963
setMessage('Success!');
60-
setSuccess(true);
6164
setIsLoading(false);
65+
refreshUser().then(() => navigate('/dashboard/repo'));
6266
})
6367
.catch(function (error) {
6468
if (error.response.status === 307) {
@@ -75,13 +79,6 @@ export default function UserProfile() {
7579
event.preventDefault();
7680
}
7781

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-
8582
return (
8683
<form onSubmit={handleSubmit}>
8784
<Snackbar

0 commit comments

Comments
 (0)