aaspai-authx 0.0.4 → 0.0.6
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/dist/express/index.cjs +1 -1
- package/dist/express/index.cjs.map +1 -1
- package/dist/express/index.js +1 -1
- package/dist/express/index.js.map +1 -1
- package/dist/index.cjs +3 -218
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -112
- package/dist/index.d.ts +1 -112
- package/dist/index.js +2 -206
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +1 -1
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.js +1 -1
- package/dist/nest/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { i as express } from './index-KOTz0ZcH.cjs';
|
|
2
2
|
export { nest } from './nest/index.cjs';
|
|
3
3
|
import { Request, Response, NextFunction } from 'express';
|
|
4
|
-
import * as aaspai_types from 'aaspai-types';
|
|
5
4
|
import { AuthXUser, AuthXSession } from 'aaspai-types';
|
|
6
5
|
import * as bson from 'bson';
|
|
7
6
|
import * as mongoose from 'mongoose';
|
|
@@ -10,9 +9,6 @@ import * as _nestjs_passport from '@nestjs/passport';
|
|
|
10
9
|
import * as _nestjs_common from '@nestjs/common';
|
|
11
10
|
import { ExecutionContext } from '@nestjs/common';
|
|
12
11
|
import { Strategy } from 'passport';
|
|
13
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
14
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
15
|
-
import { ReactNode } from 'react';
|
|
16
12
|
import 'mongodb';
|
|
17
13
|
|
|
18
14
|
/**
|
|
@@ -1310,111 +1306,4 @@ declare class AuthXStrategy extends Strategy {
|
|
|
1310
1306
|
*/
|
|
1311
1307
|
declare function createAuthXStrategy(): AuthXStrategy;
|
|
1312
1308
|
|
|
1313
|
-
|
|
1314
|
-
* Get the current authenticated session in Next.js App Router
|
|
1315
|
-
* Reads the access_token cookie (or authorization header) and verifies the JWT
|
|
1316
|
-
* @returns Session object or null if not authenticated
|
|
1317
|
-
*/
|
|
1318
|
-
declare function authx(): Promise<{
|
|
1319
|
-
session: AuthXSession | null;
|
|
1320
|
-
}>;
|
|
1321
|
-
|
|
1322
|
-
/**
|
|
1323
|
-
* Type for Next.js route handler
|
|
1324
|
-
*/
|
|
1325
|
-
type NextRouteHandler = (req: NextRequest, context?: any) => Promise<NextResponse> | NextResponse;
|
|
1326
|
-
type AuthRouteHandler = (req: NextRequest, session: AuthXSession, context?: any) => Promise<NextResponse> | NextResponse;
|
|
1327
|
-
/**
|
|
1328
|
-
* Wrap a Next.js route handler with authentication and optional permission check
|
|
1329
|
-
* @param permission - Optional permission string to require
|
|
1330
|
-
* @param handler - The route handler function
|
|
1331
|
-
* @returns Wrapped handler that checks authentication/permissions
|
|
1332
|
-
*/
|
|
1333
|
-
declare function withAuthRoute(permission: string, handler: AuthRouteHandler): NextRouteHandler;
|
|
1334
|
-
declare function withAuthRoute(handler: AuthRouteHandler): NextRouteHandler;
|
|
1335
|
-
|
|
1336
|
-
interface AuthXContextValue {
|
|
1337
|
-
session: AuthXSession | null;
|
|
1338
|
-
isLoading: boolean;
|
|
1339
|
-
error: Error | null;
|
|
1340
|
-
refetch: () => Promise<void>;
|
|
1341
|
-
}
|
|
1342
|
-
interface AuthXProviderProps {
|
|
1343
|
-
children: ReactNode;
|
|
1344
|
-
apiUrl?: string;
|
|
1345
|
-
}
|
|
1346
|
-
/**
|
|
1347
|
-
* AuthX Provider component
|
|
1348
|
-
* Provides authentication context to the application
|
|
1349
|
-
* Fetches session from /auth/me endpoint
|
|
1350
|
-
*/
|
|
1351
|
-
declare function AuthXProvider({ children, apiUrl }: AuthXProviderProps): react_jsx_runtime.JSX.Element;
|
|
1352
|
-
/**
|
|
1353
|
-
* Hook to access AuthX context
|
|
1354
|
-
* @throws Error if used outside AuthXProvider
|
|
1355
|
-
*/
|
|
1356
|
-
declare function useAuthXContext(): AuthXContextValue;
|
|
1357
|
-
|
|
1358
|
-
interface HasPermissionProps {
|
|
1359
|
-
permission: string;
|
|
1360
|
-
children: ReactNode;
|
|
1361
|
-
fallback?: ReactNode;
|
|
1362
|
-
}
|
|
1363
|
-
/**
|
|
1364
|
-
* Component that only renders children when user has the specified permission
|
|
1365
|
-
*/
|
|
1366
|
-
declare function HasPermission({ permission, children, fallback, }: HasPermissionProps): react_jsx_runtime.JSX.Element | null;
|
|
1367
|
-
|
|
1368
|
-
interface HasRoleProps {
|
|
1369
|
-
role: string | string[];
|
|
1370
|
-
children: ReactNode;
|
|
1371
|
-
fallback?: ReactNode;
|
|
1372
|
-
}
|
|
1373
|
-
/**
|
|
1374
|
-
* Component that only renders children when user has the specified role(s)
|
|
1375
|
-
*/
|
|
1376
|
-
declare function HasRole({ role, children, fallback }: HasRoleProps): react_jsx_runtime.JSX.Element | null;
|
|
1377
|
-
|
|
1378
|
-
interface SignedInProps {
|
|
1379
|
-
children: ReactNode;
|
|
1380
|
-
fallback?: ReactNode;
|
|
1381
|
-
}
|
|
1382
|
-
/**
|
|
1383
|
-
* Component that only renders children when user is signed in
|
|
1384
|
-
*/
|
|
1385
|
-
declare function SignedIn({ children, fallback }: SignedInProps): react_jsx_runtime.JSX.Element | null;
|
|
1386
|
-
|
|
1387
|
-
interface SignedOutProps {
|
|
1388
|
-
children: ReactNode;
|
|
1389
|
-
fallback?: ReactNode;
|
|
1390
|
-
}
|
|
1391
|
-
/**
|
|
1392
|
-
* Component that only renders children when user is signed out
|
|
1393
|
-
*/
|
|
1394
|
-
declare function SignedOut({ children, fallback }: SignedOutProps): react_jsx_runtime.JSX.Element | null;
|
|
1395
|
-
|
|
1396
|
-
/**
|
|
1397
|
-
* Hook to access the current authentication session
|
|
1398
|
-
* @returns Object with session, isLoading, error, and refetch function
|
|
1399
|
-
*/
|
|
1400
|
-
declare function useAuthX(): {
|
|
1401
|
-
session: aaspai_types.AuthXSession | null;
|
|
1402
|
-
isLoading: boolean;
|
|
1403
|
-
error: Error | null;
|
|
1404
|
-
refetch: () => Promise<void>;
|
|
1405
|
-
isSignedIn: boolean;
|
|
1406
|
-
userId: string | null;
|
|
1407
|
-
email: string | null;
|
|
1408
|
-
roles: string[];
|
|
1409
|
-
permissions: string[];
|
|
1410
|
-
};
|
|
1411
|
-
/**
|
|
1412
|
-
* Hook to check if user has a specific role
|
|
1413
|
-
*/
|
|
1414
|
-
declare function useHasRole(role: string): boolean;
|
|
1415
|
-
/**
|
|
1416
|
-
* Hook to check if user has a specific permission
|
|
1417
|
-
*/
|
|
1418
|
-
declare function useHasPermission(permission: string): boolean;
|
|
1419
|
-
|
|
1420
|
-
export { AuthAdminService, AuthXGuard, AuthXProvider, AuthXSessionDecorator, AuthXStrategy, EmailService, HasPermission, HasRole, PLATFORM_ROLES, Permissions, ProjectsService, Roles, SignedIn, SignedOut, UploadsService, authorize, authx, buildSession, createAuthXStrategy, getPermissionsForRoles, hasAllPermissions, hasAllRoles, hasAnyPermission, hasAnyRole, hasPermission, hasRole, requireAuth, requirePermission, requirePermission$1 as requirePermissionLegacy, requireRole, useAuthX, useAuthXContext, useHasPermission, useHasRole, withAuthRoute };
|
|
1309
|
+
export { AuthAdminService, AuthXGuard, AuthXSessionDecorator, AuthXStrategy, EmailService, PLATFORM_ROLES, Permissions, ProjectsService, Roles, UploadsService, authorize, buildSession, createAuthXStrategy, getPermissionsForRoles, hasAllPermissions, hasAllRoles, hasAnyPermission, hasAnyRole, hasPermission, hasRole, requireAuth, requirePermission, requirePermission$1 as requirePermissionLegacy, requireRole };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { i as express } from './index-KOTz0ZcH.js';
|
|
2
2
|
export { nest } from './nest/index.js';
|
|
3
3
|
import { Request, Response, NextFunction } from 'express';
|
|
4
|
-
import * as aaspai_types from 'aaspai-types';
|
|
5
4
|
import { AuthXUser, AuthXSession } from 'aaspai-types';
|
|
6
5
|
import * as bson from 'bson';
|
|
7
6
|
import * as mongoose from 'mongoose';
|
|
@@ -10,9 +9,6 @@ import * as _nestjs_passport from '@nestjs/passport';
|
|
|
10
9
|
import * as _nestjs_common from '@nestjs/common';
|
|
11
10
|
import { ExecutionContext } from '@nestjs/common';
|
|
12
11
|
import { Strategy } from 'passport';
|
|
13
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
14
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
15
|
-
import { ReactNode } from 'react';
|
|
16
12
|
import 'mongodb';
|
|
17
13
|
|
|
18
14
|
/**
|
|
@@ -1310,111 +1306,4 @@ declare class AuthXStrategy extends Strategy {
|
|
|
1310
1306
|
*/
|
|
1311
1307
|
declare function createAuthXStrategy(): AuthXStrategy;
|
|
1312
1308
|
|
|
1313
|
-
|
|
1314
|
-
* Get the current authenticated session in Next.js App Router
|
|
1315
|
-
* Reads the access_token cookie (or authorization header) and verifies the JWT
|
|
1316
|
-
* @returns Session object or null if not authenticated
|
|
1317
|
-
*/
|
|
1318
|
-
declare function authx(): Promise<{
|
|
1319
|
-
session: AuthXSession | null;
|
|
1320
|
-
}>;
|
|
1321
|
-
|
|
1322
|
-
/**
|
|
1323
|
-
* Type for Next.js route handler
|
|
1324
|
-
*/
|
|
1325
|
-
type NextRouteHandler = (req: NextRequest, context?: any) => Promise<NextResponse> | NextResponse;
|
|
1326
|
-
type AuthRouteHandler = (req: NextRequest, session: AuthXSession, context?: any) => Promise<NextResponse> | NextResponse;
|
|
1327
|
-
/**
|
|
1328
|
-
* Wrap a Next.js route handler with authentication and optional permission check
|
|
1329
|
-
* @param permission - Optional permission string to require
|
|
1330
|
-
* @param handler - The route handler function
|
|
1331
|
-
* @returns Wrapped handler that checks authentication/permissions
|
|
1332
|
-
*/
|
|
1333
|
-
declare function withAuthRoute(permission: string, handler: AuthRouteHandler): NextRouteHandler;
|
|
1334
|
-
declare function withAuthRoute(handler: AuthRouteHandler): NextRouteHandler;
|
|
1335
|
-
|
|
1336
|
-
interface AuthXContextValue {
|
|
1337
|
-
session: AuthXSession | null;
|
|
1338
|
-
isLoading: boolean;
|
|
1339
|
-
error: Error | null;
|
|
1340
|
-
refetch: () => Promise<void>;
|
|
1341
|
-
}
|
|
1342
|
-
interface AuthXProviderProps {
|
|
1343
|
-
children: ReactNode;
|
|
1344
|
-
apiUrl?: string;
|
|
1345
|
-
}
|
|
1346
|
-
/**
|
|
1347
|
-
* AuthX Provider component
|
|
1348
|
-
* Provides authentication context to the application
|
|
1349
|
-
* Fetches session from /auth/me endpoint
|
|
1350
|
-
*/
|
|
1351
|
-
declare function AuthXProvider({ children, apiUrl }: AuthXProviderProps): react_jsx_runtime.JSX.Element;
|
|
1352
|
-
/**
|
|
1353
|
-
* Hook to access AuthX context
|
|
1354
|
-
* @throws Error if used outside AuthXProvider
|
|
1355
|
-
*/
|
|
1356
|
-
declare function useAuthXContext(): AuthXContextValue;
|
|
1357
|
-
|
|
1358
|
-
interface HasPermissionProps {
|
|
1359
|
-
permission: string;
|
|
1360
|
-
children: ReactNode;
|
|
1361
|
-
fallback?: ReactNode;
|
|
1362
|
-
}
|
|
1363
|
-
/**
|
|
1364
|
-
* Component that only renders children when user has the specified permission
|
|
1365
|
-
*/
|
|
1366
|
-
declare function HasPermission({ permission, children, fallback, }: HasPermissionProps): react_jsx_runtime.JSX.Element | null;
|
|
1367
|
-
|
|
1368
|
-
interface HasRoleProps {
|
|
1369
|
-
role: string | string[];
|
|
1370
|
-
children: ReactNode;
|
|
1371
|
-
fallback?: ReactNode;
|
|
1372
|
-
}
|
|
1373
|
-
/**
|
|
1374
|
-
* Component that only renders children when user has the specified role(s)
|
|
1375
|
-
*/
|
|
1376
|
-
declare function HasRole({ role, children, fallback }: HasRoleProps): react_jsx_runtime.JSX.Element | null;
|
|
1377
|
-
|
|
1378
|
-
interface SignedInProps {
|
|
1379
|
-
children: ReactNode;
|
|
1380
|
-
fallback?: ReactNode;
|
|
1381
|
-
}
|
|
1382
|
-
/**
|
|
1383
|
-
* Component that only renders children when user is signed in
|
|
1384
|
-
*/
|
|
1385
|
-
declare function SignedIn({ children, fallback }: SignedInProps): react_jsx_runtime.JSX.Element | null;
|
|
1386
|
-
|
|
1387
|
-
interface SignedOutProps {
|
|
1388
|
-
children: ReactNode;
|
|
1389
|
-
fallback?: ReactNode;
|
|
1390
|
-
}
|
|
1391
|
-
/**
|
|
1392
|
-
* Component that only renders children when user is signed out
|
|
1393
|
-
*/
|
|
1394
|
-
declare function SignedOut({ children, fallback }: SignedOutProps): react_jsx_runtime.JSX.Element | null;
|
|
1395
|
-
|
|
1396
|
-
/**
|
|
1397
|
-
* Hook to access the current authentication session
|
|
1398
|
-
* @returns Object with session, isLoading, error, and refetch function
|
|
1399
|
-
*/
|
|
1400
|
-
declare function useAuthX(): {
|
|
1401
|
-
session: aaspai_types.AuthXSession | null;
|
|
1402
|
-
isLoading: boolean;
|
|
1403
|
-
error: Error | null;
|
|
1404
|
-
refetch: () => Promise<void>;
|
|
1405
|
-
isSignedIn: boolean;
|
|
1406
|
-
userId: string | null;
|
|
1407
|
-
email: string | null;
|
|
1408
|
-
roles: string[];
|
|
1409
|
-
permissions: string[];
|
|
1410
|
-
};
|
|
1411
|
-
/**
|
|
1412
|
-
* Hook to check if user has a specific role
|
|
1413
|
-
*/
|
|
1414
|
-
declare function useHasRole(role: string): boolean;
|
|
1415
|
-
/**
|
|
1416
|
-
* Hook to check if user has a specific permission
|
|
1417
|
-
*/
|
|
1418
|
-
declare function useHasPermission(permission: string): boolean;
|
|
1419
|
-
|
|
1420
|
-
export { AuthAdminService, AuthXGuard, AuthXProvider, AuthXSessionDecorator, AuthXStrategy, EmailService, HasPermission, HasRole, PLATFORM_ROLES, Permissions, ProjectsService, Roles, SignedIn, SignedOut, UploadsService, authorize, authx, buildSession, createAuthXStrategy, getPermissionsForRoles, hasAllPermissions, hasAllRoles, hasAnyPermission, hasAnyRole, hasPermission, hasRole, requireAuth, requirePermission, requirePermission$1 as requirePermissionLegacy, requireRole, useAuthX, useAuthXContext, useHasPermission, useHasRole, withAuthRoute };
|
|
1309
|
+
export { AuthAdminService, AuthXGuard, AuthXSessionDecorator, AuthXStrategy, EmailService, PLATFORM_ROLES, Permissions, ProjectsService, Roles, UploadsService, authorize, buildSession, createAuthXStrategy, getPermissionsForRoles, hasAllPermissions, hasAllRoles, hasAnyPermission, hasAnyRole, hasPermission, hasRole, requireAuth, requirePermission, requirePermission$1 as requirePermissionLegacy, requireRole };
|
package/dist/index.js
CHANGED
|
@@ -509,7 +509,7 @@ var AuthAdminService = class {
|
|
|
509
509
|
return user;
|
|
510
510
|
}
|
|
511
511
|
async assignRealmRole(userId, roleName) {
|
|
512
|
-
const role = await RolePermissionModel.findOne({
|
|
512
|
+
const role = await RolePermissionModel.findOne({ role: roleName });
|
|
513
513
|
if (!role) throw new Error(`Role not found: ${roleName}`);
|
|
514
514
|
await OrgUser.findOneAndUpdate(
|
|
515
515
|
{ id: userId },
|
|
@@ -2003,217 +2003,18 @@ var AuthXStrategy = class extends Strategy {
|
|
|
2003
2003
|
function createAuthXStrategy() {
|
|
2004
2004
|
return new AuthXStrategy();
|
|
2005
2005
|
}
|
|
2006
|
-
|
|
2007
|
-
// src/next/server/authx.ts
|
|
2008
|
-
import { cookies } from "next/headers";
|
|
2009
|
-
async function authx() {
|
|
2010
|
-
try {
|
|
2011
|
-
const cookieStore = await cookies();
|
|
2012
|
-
const token = cookieStore.get("access_token")?.value || cookieStore.get("authorization")?.value || cookieStore.get("auth_token")?.value || null;
|
|
2013
|
-
if (!token) {
|
|
2014
|
-
return { session: null };
|
|
2015
|
-
}
|
|
2016
|
-
const claims = await verifyJwt(token);
|
|
2017
|
-
const session = buildSession(claims);
|
|
2018
|
-
return { session };
|
|
2019
|
-
} catch (error) {
|
|
2020
|
-
return { session: null };
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
|
|
2024
|
-
// src/next/server/withAuthRoute.ts
|
|
2025
|
-
import { NextResponse } from "next/server";
|
|
2026
|
-
function withAuthRoute(permissionOrHandler, handler) {
|
|
2027
|
-
let permission;
|
|
2028
|
-
let routeHandler;
|
|
2029
|
-
if (typeof permissionOrHandler === "string") {
|
|
2030
|
-
permission = permissionOrHandler;
|
|
2031
|
-
routeHandler = handler;
|
|
2032
|
-
} else {
|
|
2033
|
-
permission = void 0;
|
|
2034
|
-
routeHandler = permissionOrHandler;
|
|
2035
|
-
}
|
|
2036
|
-
return async (req, context) => {
|
|
2037
|
-
const { session } = await authx();
|
|
2038
|
-
if (!session) {
|
|
2039
|
-
return new NextResponse(
|
|
2040
|
-
JSON.stringify({ error: "Unauthorized" }),
|
|
2041
|
-
{ status: 401, headers: { "Content-Type": "application/json" } }
|
|
2042
|
-
);
|
|
2043
|
-
}
|
|
2044
|
-
if (permission && !hasPermission(session, permission)) {
|
|
2045
|
-
return new NextResponse(
|
|
2046
|
-
JSON.stringify({
|
|
2047
|
-
error: "Forbidden",
|
|
2048
|
-
reason: "MISSING_PERMISSION",
|
|
2049
|
-
permission
|
|
2050
|
-
}),
|
|
2051
|
-
{ status: 403, headers: { "Content-Type": "application/json" } }
|
|
2052
|
-
);
|
|
2053
|
-
}
|
|
2054
|
-
return routeHandler(req, session, context);
|
|
2055
|
-
};
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
// src/next/client/AuthXProvider.tsx
|
|
2059
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
2060
|
-
import { jsx } from "react/jsx-runtime";
|
|
2061
|
-
var AuthXContext = createContext(void 0);
|
|
2062
|
-
function AuthXProvider({ children, apiUrl = "/auth/me" }) {
|
|
2063
|
-
const [session, setSession] = useState(null);
|
|
2064
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
2065
|
-
const [error, setError] = useState(null);
|
|
2066
|
-
const fetchSession = async () => {
|
|
2067
|
-
try {
|
|
2068
|
-
setIsLoading(true);
|
|
2069
|
-
setError(null);
|
|
2070
|
-
const response = await fetch(apiUrl, {
|
|
2071
|
-
credentials: "include"
|
|
2072
|
-
// Include cookies
|
|
2073
|
-
});
|
|
2074
|
-
if (!response.ok) {
|
|
2075
|
-
if (response.status === 401) {
|
|
2076
|
-
setSession(null);
|
|
2077
|
-
return;
|
|
2078
|
-
}
|
|
2079
|
-
throw new Error(`Failed to fetch session: ${response.statusText}`);
|
|
2080
|
-
}
|
|
2081
|
-
const data = await response.json();
|
|
2082
|
-
setSession(data.user || data.session || data);
|
|
2083
|
-
} catch (err) {
|
|
2084
|
-
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
2085
|
-
setSession(null);
|
|
2086
|
-
} finally {
|
|
2087
|
-
setIsLoading(false);
|
|
2088
|
-
}
|
|
2089
|
-
};
|
|
2090
|
-
useEffect(() => {
|
|
2091
|
-
fetchSession();
|
|
2092
|
-
}, [apiUrl]);
|
|
2093
|
-
const value = {
|
|
2094
|
-
session,
|
|
2095
|
-
isLoading,
|
|
2096
|
-
error,
|
|
2097
|
-
refetch: fetchSession
|
|
2098
|
-
};
|
|
2099
|
-
return /* @__PURE__ */ jsx(AuthXContext.Provider, { value, children });
|
|
2100
|
-
}
|
|
2101
|
-
function useAuthXContext() {
|
|
2102
|
-
const context = useContext(AuthXContext);
|
|
2103
|
-
if (context === void 0) {
|
|
2104
|
-
throw new Error("useAuthX must be used within an AuthXProvider");
|
|
2105
|
-
}
|
|
2106
|
-
return context;
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
|
-
// src/next/client/HasPermission.tsx
|
|
2110
|
-
import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
|
|
2111
|
-
function HasPermission({
|
|
2112
|
-
permission,
|
|
2113
|
-
children,
|
|
2114
|
-
fallback = null
|
|
2115
|
-
}) {
|
|
2116
|
-
const { session, isLoading } = useAuthXContext();
|
|
2117
|
-
if (isLoading) {
|
|
2118
|
-
return null;
|
|
2119
|
-
}
|
|
2120
|
-
if (!session) {
|
|
2121
|
-
return /* @__PURE__ */ jsx2(Fragment, { children: fallback });
|
|
2122
|
-
}
|
|
2123
|
-
const hasPerm = hasPermission(session, permission);
|
|
2124
|
-
if (!hasPerm) {
|
|
2125
|
-
return /* @__PURE__ */ jsx2(Fragment, { children: fallback });
|
|
2126
|
-
}
|
|
2127
|
-
return /* @__PURE__ */ jsx2(Fragment, { children });
|
|
2128
|
-
}
|
|
2129
|
-
|
|
2130
|
-
// src/next/client/HasRole.tsx
|
|
2131
|
-
import { Fragment as Fragment2, jsx as jsx3 } from "react/jsx-runtime";
|
|
2132
|
-
function HasRole({ role, children, fallback = null }) {
|
|
2133
|
-
const { session, isLoading } = useAuthXContext();
|
|
2134
|
-
if (isLoading) {
|
|
2135
|
-
return null;
|
|
2136
|
-
}
|
|
2137
|
-
if (!session) {
|
|
2138
|
-
return /* @__PURE__ */ jsx3(Fragment2, { children: fallback });
|
|
2139
|
-
}
|
|
2140
|
-
const roles = Array.isArray(role) ? role : [role];
|
|
2141
|
-
const hasRole2 = hasAnyRole(session, roles);
|
|
2142
|
-
if (!hasRole2) {
|
|
2143
|
-
return /* @__PURE__ */ jsx3(Fragment2, { children: fallback });
|
|
2144
|
-
}
|
|
2145
|
-
return /* @__PURE__ */ jsx3(Fragment2, { children });
|
|
2146
|
-
}
|
|
2147
|
-
|
|
2148
|
-
// src/next/client/SignedIn.tsx
|
|
2149
|
-
import { Fragment as Fragment3, jsx as jsx4 } from "react/jsx-runtime";
|
|
2150
|
-
function SignedIn({ children, fallback = null }) {
|
|
2151
|
-
const { session, isLoading } = useAuthXContext();
|
|
2152
|
-
if (isLoading) {
|
|
2153
|
-
return null;
|
|
2154
|
-
}
|
|
2155
|
-
if (!session) {
|
|
2156
|
-
return /* @__PURE__ */ jsx4(Fragment3, { children: fallback });
|
|
2157
|
-
}
|
|
2158
|
-
return /* @__PURE__ */ jsx4(Fragment3, { children });
|
|
2159
|
-
}
|
|
2160
|
-
|
|
2161
|
-
// src/next/client/SignedOut.tsx
|
|
2162
|
-
import { Fragment as Fragment4, jsx as jsx5 } from "react/jsx-runtime";
|
|
2163
|
-
function SignedOut({ children, fallback = null }) {
|
|
2164
|
-
const { session, isLoading } = useAuthXContext();
|
|
2165
|
-
if (isLoading) {
|
|
2166
|
-
return null;
|
|
2167
|
-
}
|
|
2168
|
-
if (session) {
|
|
2169
|
-
return /* @__PURE__ */ jsx5(Fragment4, { children: fallback });
|
|
2170
|
-
}
|
|
2171
|
-
return /* @__PURE__ */ jsx5(Fragment4, { children });
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
// src/next/client/useAuthX.ts
|
|
2175
|
-
function useAuthX() {
|
|
2176
|
-
const { session, isLoading, error, refetch } = useAuthXContext();
|
|
2177
|
-
return {
|
|
2178
|
-
session,
|
|
2179
|
-
isLoading,
|
|
2180
|
-
error,
|
|
2181
|
-
refetch,
|
|
2182
|
-
isSignedIn: !!session,
|
|
2183
|
-
userId: session?.userId || null,
|
|
2184
|
-
email: session?.email || null,
|
|
2185
|
-
roles: session?.roles || [],
|
|
2186
|
-
permissions: session?.permissions || []
|
|
2187
|
-
};
|
|
2188
|
-
}
|
|
2189
|
-
function useHasRole(role) {
|
|
2190
|
-
const { session } = useAuthXContext();
|
|
2191
|
-
if (!session || !session.roles) return false;
|
|
2192
|
-
return session.roles.includes(role);
|
|
2193
|
-
}
|
|
2194
|
-
function useHasPermission(permission) {
|
|
2195
|
-
const { session } = useAuthXContext();
|
|
2196
|
-
if (!session || !session.permissions) return false;
|
|
2197
|
-
return session.permissions.includes(permission);
|
|
2198
|
-
}
|
|
2199
2006
|
export {
|
|
2200
2007
|
AuthAdminService,
|
|
2201
2008
|
AuthXGuard,
|
|
2202
|
-
AuthXProvider,
|
|
2203
2009
|
AuthXSessionDecorator,
|
|
2204
2010
|
AuthXStrategy,
|
|
2205
2011
|
EmailService,
|
|
2206
|
-
HasPermission,
|
|
2207
|
-
HasRole,
|
|
2208
2012
|
PLATFORM_ROLES,
|
|
2209
2013
|
Permissions,
|
|
2210
2014
|
ProjectsService,
|
|
2211
2015
|
Roles,
|
|
2212
|
-
SignedIn,
|
|
2213
|
-
SignedOut,
|
|
2214
2016
|
UploadsService,
|
|
2215
2017
|
authorize,
|
|
2216
|
-
authx,
|
|
2217
2018
|
buildSession,
|
|
2218
2019
|
createAuthXStrategy,
|
|
2219
2020
|
express_exports as express,
|
|
@@ -2228,11 +2029,6 @@ export {
|
|
|
2228
2029
|
requireAuth,
|
|
2229
2030
|
requirePermission2 as requirePermission,
|
|
2230
2031
|
requirePermission as requirePermissionLegacy,
|
|
2231
|
-
requireRole
|
|
2232
|
-
useAuthX,
|
|
2233
|
-
useAuthXContext,
|
|
2234
|
-
useHasPermission,
|
|
2235
|
-
useHasRole,
|
|
2236
|
-
withAuthRoute
|
|
2032
|
+
requireRole
|
|
2237
2033
|
};
|
|
2238
2034
|
//# sourceMappingURL=index.js.map
|