@goplusvn/core 0.1.31 → 0.1.32

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.32 — Gỡ NextAuth khỏi core (BREAKING cho app chưa migrate)
4
+
5
+ Core không còn phụ thuộc next-auth (bỏ peer dependency):
6
+
7
+ - **auth-bridge**: gỡ `nextAuthBridgeClient` + import `next-auth/react`.
8
+ Mặc định khi KHÔNG mount `AuthBridgeProvider` giờ là fallback
9
+ unauthenticated (cảnh báo console) thay vì NextAuth. App PHẢI mount
10
+ provider với client auth của mình (vinhhoa: betterAuthBridgeClient).
11
+ - **Type `Session`**: các chữ ký RBAC (`checkPermission`,
12
+ `getUserPermissions`, `hasRole`…) đổi từ `Session` của next-auth sang
13
+ `Session` cấu trúc `{ user?: unknown }` export từ `@goerp/core/types` —
14
+ session của mọi auth gán được, app không phải sửa call-site.
15
+ - `auth/proxy-gate` (gate JWT NextAuth cho app cũ) GIỮ NGUYÊN nhưng app nào
16
+ dùng phải tự cài next-auth (giờ chỉ là devDependency của core).
17
+
3
18
  ## 0.1.31 — MultiSelect: mặc định 1 DÒNG (hết lệch hàng toolbar)
4
19
 
5
20
  Wrap-mặc-định (0.1.27) làm trigger CAO LÊN khi chọn ≥2 option → lệch hàng
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@goplusvn/core",
3
3
  "description": "GoPlusVN Platform Kit - ERP kernel: layout, RBAC, CRUD, multi-tenant, system pages",
4
- "version": "0.1.31",
4
+ "version": "0.1.32",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org",
@@ -59,7 +59,6 @@
59
59
  },
60
60
  "peerDependencies": {
61
61
  "next": ">=14.0.0",
62
- "next-auth": "4.24.11",
63
62
  "react": "^18.0.0 || ^19.0.0",
64
63
  "react-dom": "^18.0.0 || ^19.0.0"
65
64
  },
package/src/auth/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // @goerp/core/auth
2
2
  // Authentication and RBAC utilities for GoERP
3
3
 
4
- import type { Session } from "next-auth";
4
+ import type { Session } from "../types";
5
5
 
6
6
  export * from "./auth-service";
7
7
 
@@ -1,5 +1,5 @@
1
1
  import type { CrudPermissions, EntityConfig } from "../../types";
2
- import type { Session } from "next-auth";
2
+ import type { Session } from "../../types";
3
3
 
4
4
  import { getCrudPermissionsFromSession } from "../../rbac/permissions";
5
5
 
package/src/rbac/index.ts CHANGED
@@ -2,8 +2,7 @@
2
2
  // Core RBAC (Role-Based Access Control) utilities for GoERP platform
3
3
  // Consolidated from packages/shared/rbac
4
4
 
5
- import type { Permission } from "../types";
6
- import type { Session } from "next-auth";
5
+ import type { Permission, Session } from "../types";
7
6
  import { logger } from "../utils";
8
7
 
9
8
  // ============================================================================
@@ -2,8 +2,7 @@
2
2
  // Server-only permission utilities - no client/UI imports
3
3
  // Use this in Server Components and API routes to avoid bundling client code
4
4
 
5
- import type { Permission } from "../types";
6
- import type { Session } from "next-auth";
5
+ import type { Permission, Session } from "../types";
7
6
 
8
7
  // ============================================================================
9
8
  // Action Mapping
@@ -13,6 +13,15 @@ import type { z } from "zod";
13
13
  export const supportedLocales = ["vi", "en"] as const;
14
14
  export type LocaleType = (typeof supportedLocales)[number];
15
15
 
16
+ /**
17
+ * Session cấu trúc — thay `import type { Session } from "next-auth"` (đã gỡ
18
+ * NextAuth khỏi core). Core chỉ cần `session?.user` rồi cast ExtendedUser;
19
+ * session của mọi auth (NextAuth cũ, Better Auth shim) đều gán được.
20
+ */
21
+ export interface Session {
22
+ user?: unknown;
23
+ }
24
+
16
25
  export interface SearchResultItem {
17
26
  id: string;
18
27
  title: string;
@@ -1,22 +1,18 @@
1
1
  "use client";
2
2
 
3
- // AUTH BRIDGE — lớp trừu tượng client-auth để core KHÔNG khóa cứng vào
4
- // NextAuth. Mặc định (không mount provider) = NextAuth y như mọi app
5
- // hiện tại không đổi hành vi. App migrate sang Better Auth chỉ cần mount:
3
+ // AUTH BRIDGE — lớp trừu tượng client-auth: core KHÔNG phụ thuộc thư viện
4
+ // auth nào. App PHẢI mount provider với client của mình, dụ Better Auth:
6
5
  //
7
6
  // <AuthBridgeProvider client={betterAuthBridgeClient}>
8
7
  //
9
- // với client map từ createAuthClient() của Better Auth (useSession /
10
- // signIn.email / signOut). LƯU Ý: client phải là hằng số suốt vòng đời app
11
- // (rules of hooks — useSession của bridge được gọi như một hook).
8
+ // với client map từ createAuthClient() (useSession / signIn.email / signOut).
9
+ // LƯU Ý: client phải là hằng số suốt vòng đời app (rules of hooks — useSession
10
+ // của bridge được gọi như một hook). Từ 0.1.32 core đã GỠ next-auth: không
11
+ // còn nextAuthBridgeClient mặc định; app còn dùng NextAuth tự viết client
12
+ // (map useSession/signIn/signOut của next-auth/react vào AuthBridgeClient).
12
13
 
13
14
  import { createContext, useContext } from "react";
14
15
  import type { ReactNode } from "react";
15
- import {
16
- signIn as nextAuthSignIn,
17
- signOut as nextAuthSignOut,
18
- useSession as nextAuthUseSession,
19
- } from "next-auth/react";
20
16
 
21
17
  export interface AuthSessionState {
22
18
  /** Session object (shape do app quyết — core chỉ đọc user.id/permissions...) */
@@ -37,31 +33,33 @@ export interface AuthBridgeClient {
37
33
  signOut: (options?: { callbackUrl?: string }) => Promise<void>;
38
34
  }
39
35
 
40
- /** Mặc định: NextAuth (v4) — các app chưa migrate dùng nguyên như cũ. */
41
- export const nextAuthBridgeClient: AuthBridgeClient = {
36
+ const MISSING_PROVIDER_MSG =
37
+ "[goerp-core] AuthBridgeProvider chưa được mount — bọc app trong " +
38
+ '<AuthBridgeProvider client={...}> với client auth của app (xem ui/auth).';
39
+
40
+ let warnedMissingProvider = false;
41
+
42
+ /**
43
+ * Fallback khi app QUÊN mount AuthBridgeProvider: session luôn
44
+ * unauthenticated (cảnh báo console 1 lần), signIn trả lỗi rõ ràng.
45
+ */
46
+ const missingProviderClient: AuthBridgeClient = {
42
47
  useSession: () => {
43
- // eslint-disable-next-line react-hooks/rules-of-hooks -- được gọi trong hook useAuthSession
44
- const s = nextAuthUseSession();
45
- return {
46
- data: s.data,
47
- status: s.status,
48
- update: () => s.update(),
49
- };
50
- },
51
- signInWithCredentials: async ({ email, password }) => {
52
- const result = await nextAuthSignIn("credentials", {
53
- redirect: false,
54
- email,
55
- password,
56
- });
57
- return { error: result?.error ?? null };
48
+ if (!warnedMissingProvider) {
49
+ warnedMissingProvider = true;
50
+ console.warn(MISSING_PROVIDER_MSG);
51
+ }
52
+ return { data: null, status: "unauthenticated", update: async () => null };
58
53
  },
59
- signOut: async (options) => {
60
- await nextAuthSignOut(options);
54
+ signInWithCredentials: async () => ({ error: MISSING_PROVIDER_MSG }),
55
+ signOut: async () => {
56
+ console.warn(MISSING_PROVIDER_MSG);
61
57
  },
62
58
  };
63
59
 
64
- const AuthBridgeContext = createContext<AuthBridgeClient>(nextAuthBridgeClient);
60
+ const AuthBridgeContext = createContext<AuthBridgeClient>(
61
+ missingProviderClient,
62
+ );
65
63
 
66
64
  export function AuthBridgeProvider({
67
65
  client,