mirror of
https://github.com/hexastack/hexabot
synced 2025-04-24 16:27:23 +00:00
fix: bug when we have dynamic route default redirection to '/'
This commit is contained in:
parent
1289ba886b
commit
8089206df1
@ -6,7 +6,6 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { useContext } from "react";
|
import { useContext } from "react";
|
||||||
|
|
||||||
@ -33,12 +32,14 @@ export const useAuth = () => {
|
|||||||
|
|
||||||
export const useLogoutRedirection = () => {
|
export const useLogoutRedirection = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const isDynamicPath = router.pathname.includes("[");
|
||||||
const hasPublicPath = PUBLIC_PATHS.includes(router.pathname);
|
const hasPublicPath = PUBLIC_PATHS.includes(router.pathname);
|
||||||
|
const encodedPath = isDynamicPath
|
||||||
|
? encodeURIComponent("/settings")
|
||||||
|
: encodeURIComponent(router.pathname);
|
||||||
const logoutRedirection = async (fullReload: boolean = false) => {
|
const logoutRedirection = async (fullReload: boolean = false) => {
|
||||||
if (!hasPublicPath) {
|
if (!hasPublicPath) {
|
||||||
const redirectUrl = `/${RouterType.LOGIN}?redirect=${encodeURIComponent(
|
const redirectUrl = `/${RouterType.LOGIN}?redirect=${encodedPath}`;
|
||||||
router.pathname,
|
|
||||||
)}`;
|
|
||||||
|
|
||||||
if (fullReload) {
|
if (fullReload) {
|
||||||
window.location.replace(redirectUrl);
|
window.location.replace(redirectUrl);
|
||||||
|
Loading…
Reference in New Issue
Block a user