mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(web): correctly replace logout url (#316)
* chore(ErrorPage): clean up code, fix typo fix(Logout): replace /logout URL after logging out to / * chore: remove needless TS type export
This commit is contained in:
parent
a84a7364e2
commit
bb2641f447
3 changed files with 14 additions and 13 deletions
|
@ -3,20 +3,15 @@ import type { FallbackProps } from "react-error-boundary";
|
||||||
import { RefreshIcon } from "@heroicons/react/solid";
|
import { RefreshIcon } from "@heroicons/react/solid";
|
||||||
|
|
||||||
export const ErrorPage = ({ error, resetErrorBoundary }: FallbackProps) => {
|
export const ErrorPage = ({ error, resetErrorBoundary }: FallbackProps) => {
|
||||||
const stack = new StackTracey(error).withSources();
|
const stack = new StackTracey(error);
|
||||||
const summary = stack.clean().asTable({
|
const summary = stack.clean().asTable({
|
||||||
maxColumnWidths: {
|
maxColumnWidths: {
|
||||||
callee: 48,
|
callee: 48,
|
||||||
file: 48,
|
file: 48,
|
||||||
sourceLine: 256
|
sourceLine: 384
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const type = String(
|
|
||||||
(error && error.constructor && error.constructor.name)
|
|
||||||
|| typeof (error)
|
|
||||||
);
|
|
||||||
const msg = String(error && error.message);
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex flex-col justify-center py-12 sm:px-6 lg:px-8">
|
<div className="min-h-screen flex flex-col justify-center py-12 sm:px-6 lg:px-8">
|
||||||
<div className="sm:mx-auto sm:w-full sm:max-w-screen-md md:max-w-screen-lg lg:max-w-screen-xl">
|
<div className="sm:mx-auto sm:w-full sm:max-w-screen-md md:max-w-screen-lg lg:max-w-screen-xl">
|
||||||
|
@ -59,7 +54,7 @@ export const ErrorPage = ({ error, resetErrorBoundary }: FallbackProps) => {
|
||||||
clipRule="evenodd"
|
clipRule="evenodd"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
<h3 className="text-lg font-medium text-red-700 dark:text-red-800">{type}: {msg}</h3>
|
<h3 className="text-lg font-medium text-red-700 dark:text-red-800">{error.toString()}</h3>
|
||||||
</div>
|
</div>
|
||||||
{summary ? (
|
{summary ? (
|
||||||
<pre className="mt-2 mb-4 text-sm text-red-700 dark:text-red-800 overflow-x-auto">
|
<pre className="mt-2 mb-4 text-sm text-red-700 dark:text-red-800 overflow-x-auto">
|
||||||
|
@ -67,7 +62,7 @@ export const ErrorPage = ({ error, resetErrorBoundary }: FallbackProps) => {
|
||||||
</pre>
|
</pre>
|
||||||
) : null}
|
) : null}
|
||||||
<span className="block text-gray-800 mb-2 text-md">
|
<span className="block text-gray-800 mb-2 text-md">
|
||||||
You can try resetting the page page using the button provided below.
|
You can try resetting the page state using the button provided below.
|
||||||
However, this is not guaranteed to fix the error.
|
However, this is not guaranteed to fix the error.
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
|
@ -85,4 +80,4 @@ export const ErrorPage = ({ error, resetErrorBoundary }: FallbackProps) => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { APIClient } from "../../api/APIClient";
|
||||||
import { AuthContext } from "../../utils/Context";
|
import { AuthContext } from "../../utils/Context";
|
||||||
import { PasswordInput, TextInput } from "../../components/inputs/text";
|
import { PasswordInput, TextInput } from "../../components/inputs/text";
|
||||||
|
|
||||||
export type LoginFormFields = {
|
type LoginFormFields = {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,19 +1,25 @@
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
import { APIClient } from "../../api/APIClient";
|
import { APIClient } from "../../api/APIClient";
|
||||||
import Toast from "../../components/notifications/Toast";
|
|
||||||
import { AuthContext } from "../../utils/Context";
|
import { AuthContext } from "../../utils/Context";
|
||||||
|
import Toast from "../../components/notifications/Toast";
|
||||||
|
|
||||||
export const Logout = () => {
|
export const Logout = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
useEffect(
|
useEffect(
|
||||||
() => {
|
() => {
|
||||||
APIClient.auth.logout()
|
APIClient.auth.logout()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
AuthContext.reset();
|
||||||
toast.custom((t) => (
|
toast.custom((t) => (
|
||||||
<Toast type="success" body="You have been logged out. Goodbye!" t={t} />
|
<Toast type="success" body="You have been logged out. Goodbye!" t={t} />
|
||||||
));
|
));
|
||||||
AuthContext.reset();
|
|
||||||
|
// Dirty way to fix URL without triggering a re-render.
|
||||||
|
// Ideally, we'd move the logout component to a function.
|
||||||
|
setInterval(() => navigate("/", { replace: true }), 250);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue