Fix error login
This commit is contained in:
parent
e795419b78
commit
852459fdc2
7
src/app/dashboard/coba/page.tsx
Normal file
7
src/app/dashboard/coba/page.tsx
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
<div>page</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -1,6 +1,12 @@
|
|||
import checkPermission from '@/modules/auth/utils/checkPermission'
|
||||
import dashboardConfig from '@/modules/dashboard/dashboard.config'
|
||||
import { redirect } from 'next/navigation'
|
||||
import React from 'react'
|
||||
|
||||
export default async function Dashboard() {
|
||||
|
||||
if (!await checkPermission("authenticated-only")) redirect(`${dashboardConfig.baseRoute}/login`)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className='font-bold bg-red-500'>Dashboard</h1>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
import { redirect } from 'next/navigation'
|
||||
import React from 'react'
|
||||
|
||||
export default function page() {
|
||||
|
||||
redirect("/dashboard")
|
||||
|
||||
return (
|
||||
<div>page</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -35,10 +35,11 @@ export default async function getMyDetailAction(): Promise<ServerResponseAction<
|
|||
if (e instanceof AuthError && e.errorCode === "INVALID_JWT_TOKEN") {
|
||||
return {
|
||||
success: false,
|
||||
error: new BaseError({
|
||||
errorCode: e.errorCode,
|
||||
error: {
|
||||
errorCode: "UNAUTHENTICATED",
|
||||
message: "You are not authenticated",
|
||||
}),
|
||||
},
|
||||
dashboardError: true
|
||||
};
|
||||
}
|
||||
// Handle other types of errors.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import React, { ReactElement, ReactNode, createContext, useCallback, useContext,
|
|||
import { notifications } from "@mantine/notifications";
|
||||
import getMyDetailAction from "../actions/getMyDetailAction";
|
||||
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
||||
import ClientError from "@/core/error/ClientError";
|
||||
|
||||
// Defining the structure for user data within the authentication context.
|
||||
interface UserData {
|
||||
|
|
@ -48,6 +49,9 @@ export const AuthContextProvider = ({ children }: Props): ReactElement => {
|
|||
setUser(response.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof ClientError){
|
||||
if (error.errorCode === "UNAUTHENTICATED") return;
|
||||
}
|
||||
notifications.show({
|
||||
title: 'Error',
|
||||
message: 'Error while retrieving user data',
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
"use client";
|
||||
import React, { useEffect } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { AppShell } from "@mantine/core";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
|
||||
import AppHeader from "./AppHeader";
|
||||
import AppNavbar from "./AppNavbar";
|
||||
import { useAuth } from "@/modules/auth/contexts/AuthContext";
|
||||
import { usePathname } from "next/navigation";
|
||||
import dashboardConfig from "../dashboard.config";
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
|
|
@ -20,16 +22,25 @@ interface Props {
|
|||
* @returns A React element representing the dashboard layout.
|
||||
*/
|
||||
export default function DashboardLayout(props: Props) {
|
||||
|
||||
const pathname = usePathname();
|
||||
|
||||
// State and toggle function for handling the disclosure of the navigation bar
|
||||
const [openNavbar, { toggle }] = useDisclosure(false);
|
||||
|
||||
const {fetchUserData} = useAuth();
|
||||
|
||||
const [withAppShell, setWithAppShell] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
fetchUserData()
|
||||
}, [fetchUserData])
|
||||
|
||||
return (
|
||||
useEffect(() => {
|
||||
setWithAppShell(!dashboardConfig.routesWithoutAppShell.some(v => `${dashboardConfig.baseRoute}${v}` === pathname))
|
||||
}, [pathname])
|
||||
|
||||
return withAppShell ? (
|
||||
<AppShell
|
||||
padding="md"
|
||||
header={{ height: 70 }}
|
||||
|
|
@ -49,5 +60,5 @@ export default function DashboardLayout(props: Props) {
|
|||
{props.children}
|
||||
</AppShell.Main>
|
||||
</AppShell>
|
||||
);
|
||||
) : props.children;
|
||||
}
|
||||
|
|
|
|||
9
src/modules/dashboard/dashboard.config.ts
Normal file
9
src/modules/dashboard/dashboard.config.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
const dashboardConfig = {
|
||||
routesWithoutAppShell : [
|
||||
"/login",
|
||||
"/register",
|
||||
],
|
||||
baseRoute: "/dashboard"
|
||||
} as const;
|
||||
|
||||
export default dashboardConfig;
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import ClientError from "@/core/error/ClientError";
|
||||
import ServerResponseAction from "../types/ServerResponseAction";
|
||||
import { error } from "console";
|
||||
|
||||
/**
|
||||
* A higher-order function that wraps an async function and provides structured error handling.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user