nucleus-core-ts 0.9.77 → 0.9.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { usePathname, useRouter } from "next/navigation";
|
|
4
|
+
import {
|
|
5
|
+
LoginChecker,
|
|
6
|
+
RoleChecker,
|
|
7
|
+
type AuthGuardConfig,
|
|
8
|
+
type AuthGuardMeResponse,
|
|
9
|
+
} from "nucleus-core-ts/fe/auth";
|
|
10
|
+
import { useApiActions } from "@/lib/api/hook";
|
|
11
|
+
|
|
12
|
+
const AUTH_CONFIG: Omit<AuthGuardConfig, "fetchUser"> = {
|
|
13
|
+
unauthPaths: [
|
|
14
|
+
"/login",
|
|
15
|
+
"/register",
|
|
16
|
+
"/reset-password",
|
|
17
|
+
"/forgot-password",
|
|
18
|
+
"/verify-magic-link",
|
|
19
|
+
"/set-password",
|
|
20
|
+
"/verify-email",
|
|
21
|
+
],
|
|
22
|
+
publicPaths: ["/error", "/not-found", "/forbidden"],
|
|
23
|
+
loginPath: "/login",
|
|
24
|
+
globalRoleGate: [],
|
|
25
|
+
routeRequirements: {},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type AuthWrapperProps = {
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function AuthWrapper({ children }: AuthWrapperProps) {
|
|
33
|
+
const actions = useApiActions();
|
|
34
|
+
const pathname = usePathname();
|
|
35
|
+
const router = useRouter();
|
|
36
|
+
|
|
37
|
+
const config: AuthGuardConfig = {
|
|
38
|
+
...AUTH_CONFIG,
|
|
39
|
+
fetchUser: ({ onSuccess, onError }) => {
|
|
40
|
+
actions.ME.start({
|
|
41
|
+
payload: undefined,
|
|
42
|
+
onAfterHandle: (data) => {
|
|
43
|
+
const d = data.data;
|
|
44
|
+
if (d) {
|
|
45
|
+
const meData = d as unknown as AuthGuardMeResponse;
|
|
46
|
+
onSuccess(meData);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
onErrorHandle: (error, code) => {
|
|
50
|
+
onError(error, code);
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<LoginChecker config={config} pathname={pathname} onNavigate={router.push}>
|
|
58
|
+
<RoleChecker config={config} pathname={pathname}>
|
|
59
|
+
{children}
|
|
60
|
+
</RoleChecker>
|
|
61
|
+
</LoginChecker>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -1,30 +1,35 @@
|
|
|
1
|
-
import type { Metadata } from
|
|
2
|
-
import { Geist, Geist_Mono } from
|
|
3
|
-
import
|
|
1
|
+
import type { Metadata } from "next";
|
|
2
|
+
import { Geist, Geist_Mono } from "next/font/google";
|
|
3
|
+
import { AuthWrapper } from "./_components/AuthWrapper";
|
|
4
|
+
import "./globals.css";
|
|
4
5
|
|
|
5
6
|
const geistSans = Geist({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})
|
|
7
|
+
variable: "--font-geist-sans",
|
|
8
|
+
subsets: ["latin"],
|
|
9
|
+
});
|
|
9
10
|
|
|
10
11
|
const geistMono = Geist_Mono({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})
|
|
12
|
+
variable: "--font-geist-mono",
|
|
13
|
+
subsets: ["latin"],
|
|
14
|
+
});
|
|
14
15
|
|
|
15
16
|
export const metadata: Metadata = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
17
|
+
title: "{{APP_NAME}}",
|
|
18
|
+
description: "{{APP_DESCRIPTION}}",
|
|
19
|
+
};
|
|
19
20
|
|
|
20
21
|
export default function RootLayout({
|
|
21
|
-
|
|
22
|
+
children,
|
|
22
23
|
}: Readonly<{
|
|
23
|
-
|
|
24
|
+
children: React.ReactNode;
|
|
24
25
|
}>) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
return (
|
|
27
|
+
<html lang="en">
|
|
28
|
+
<body
|
|
29
|
+
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
|
30
|
+
>
|
|
31
|
+
<AuthWrapper>{children}</AuthWrapper>
|
|
32
|
+
</body>
|
|
33
|
+
</html>
|
|
34
|
+
);
|
|
30
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nucleus-core-ts",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.78",
|
|
4
4
|
"description": "Production-ready, enterprise-grade TypeScript framework for building multi-tenant APIs",
|
|
5
5
|
"author": "Hidayet Can Özcan <hidayetcan@gmail.com>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"types": "./dist/fe/index.d.ts",
|
|
39
39
|
"import": "./dist/fe/index.js"
|
|
40
40
|
},
|
|
41
|
+
"./fe/auth": {
|
|
42
|
+
"types": "./dist/fe/components/AuthGuard/index.d.ts",
|
|
43
|
+
"import": "./dist/fe/components/AuthGuard/index.js"
|
|
44
|
+
},
|
|
41
45
|
"./proxy": {
|
|
42
46
|
"types": "./dist/src/Client/Proxy/index.d.ts",
|
|
43
47
|
"import": "./dist/src/Client/Proxy/index.js"
|