Fix token refresh issues
This commit is contained in:
@@ -2,12 +2,14 @@ import PrimaryButton from "@/components/button/PrimaryButton";
|
||||
import PasswordInput from "@/components/input/PasswordInput";
|
||||
import TextInput from "@/components/input/TextInput";
|
||||
import { useAuth } from "@/providers/AuthProvider";
|
||||
import { useTimedModal } from "@/providers/TimedModalProvider";
|
||||
import { Navigate, useNavigate } from "react-router";
|
||||
|
||||
|
||||
export default function LoginPage(){
|
||||
const { jwt, setJwt } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const { addSuccessMessage, addErrorMessage } = useTimedModal();
|
||||
|
||||
|
||||
const login = async (formData: FormData) => {
|
||||
@@ -15,22 +17,27 @@ export default function LoginPage(){
|
||||
const password = formData.get("password") as string;
|
||||
|
||||
|
||||
const response = await fetch(`${import.meta.env.VITE_API_URL}/auth/token`, {
|
||||
await fetch(`${import.meta.env.VITE_API_URL}/auth/token`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: "Basic " + btoa(`${username}:${password}`)
|
||||
},
|
||||
credentials: "include"
|
||||
})
|
||||
.then(async (response) => {
|
||||
if(response.status === 200){
|
||||
addSuccessMessage("Logged in successfully");
|
||||
const json = await response.json();
|
||||
setJwt(json.token);
|
||||
navigate("/raidGroup");
|
||||
}
|
||||
else{
|
||||
addErrorMessage("Failed to log in: " + ((await response.json()).errors as string[]).join(",\n"));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
addErrorMessage("Failed to log in: " + error);
|
||||
});
|
||||
|
||||
if(response.status === 200){
|
||||
const json = await response.json();
|
||||
setJwt(json.token);
|
||||
navigate("/raidGroup");
|
||||
}
|
||||
else{
|
||||
//TODO: Handle error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user