@jengolabs/auth-react 0.1.0

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,13 @@
1
+ import { createAuthClient } from "better-auth/react";
2
+ import { organizationClient } from "better-auth/client/plugins";
3
+ interface JengoAuthConfig {
4
+ authUrl: string;
5
+ }
6
+ type OrganizationPlugin = ReturnType<typeof organizationClient>;
7
+ type JengoAuthClientShape = ReturnType<typeof createAuthClient<{
8
+ plugins: [OrganizationPlugin];
9
+ }>>;
10
+ export type JengoAuthClient = JengoAuthClientShape;
11
+ export declare function createJengoAuthClient(config: JengoAuthConfig): JengoAuthClientShape;
12
+ export {};
13
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,UAAU,eAAe;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEhE,KAAK,oBAAoB,GAAG,UAAU,CACpC,OAAO,gBAAgB,CAAC;IAAE,OAAO,EAAE,CAAC,kBAAkB,CAAC,CAAA;CAAE,CAAC,CAC3D,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAEnD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,eAAe,GACtB,oBAAoB,CAMtB"}
package/dist/client.js ADDED
@@ -0,0 +1,10 @@
1
+ import { createAuthClient } from "better-auth/react";
2
+ import { organizationClient } from "better-auth/client/plugins";
3
+ export function createJengoAuthClient(config) {
4
+ return createAuthClient({
5
+ baseURL: config.authUrl,
6
+ fetchOptions: { credentials: "include" },
7
+ plugins: [organizationClient()],
8
+ });
9
+ }
10
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAchE,MAAM,UAAU,qBAAqB,CACnC,MAAuB;IAEvB,OAAO,gBAAgB,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,YAAY,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE;QACxC,OAAO,EAAE,CAAC,kBAAkB,EAAE,CAAC;KAChC,CAAyB,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ReactNode } from "react";
2
+ interface ProtectedRouteProps {
3
+ authUrl: string;
4
+ children: ReactNode;
5
+ fallback?: ReactNode;
6
+ redirectTo?: string;
7
+ }
8
+ export declare function ProtectedRoute({ authUrl, children, fallback, redirectTo, }: ProtectedRouteProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
9
+ export {};
10
+ //# sourceMappingURL=protected-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protected-route.d.ts","sourceRoot":"","sources":["../../src/components/protected-route.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,UAAU,mBAAmB;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,UAAU,GACX,EAAE,mBAAmB,+TAcrB"}
@@ -0,0 +1,16 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useSession } from "../hooks/use-session";
3
+ export function ProtectedRoute({ authUrl, children, fallback, redirectTo, }) {
4
+ const { data: session, isPending } = useSession(authUrl);
5
+ if (isPending)
6
+ return fallback ?? null;
7
+ if (!session) {
8
+ if (redirectTo && typeof window !== "undefined") {
9
+ window.location.href = redirectTo;
10
+ return null;
11
+ }
12
+ return null;
13
+ }
14
+ return _jsx(_Fragment, { children: children });
15
+ }
16
+ //# sourceMappingURL=protected-route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protected-route.js","sourceRoot":"","sources":["../../src/components/protected-route.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAUlD,MAAM,UAAU,cAAc,CAAC,EAC7B,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,UAAU,GACU;IACpB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEzD,IAAI,SAAS;QAAE,OAAO,QAAQ,IAAI,IAAI,CAAC;IAEvC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,IAAI,UAAU,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAChD,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,UAAU,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,4BAAG,QAAQ,GAAI,CAAC;AACzB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function useAuthFetch(authUrl: string): (url: string, options?: RequestInit) => Promise<Response>;
2
+ //# sourceMappingURL=use-auth-fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-auth-fetch.d.ts","sourceRoot":"","sources":["../../src/hooks/use-auth-fetch.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,IAG5B,KAAK,MAAM,EAAE,UAAS,WAAgB,uBAerD"}
@@ -0,0 +1,18 @@
1
+ import { getAuthClient } from "./use-session";
2
+ export function useAuthFetch(authUrl) {
3
+ const client = getAuthClient(authUrl);
4
+ return async (url, options = {}) => {
5
+ const session = await client.getSession();
6
+ if (!session?.data) {
7
+ throw new Error("Not authenticated");
8
+ }
9
+ return fetch(url, {
10
+ ...options,
11
+ headers: {
12
+ ...options.headers,
13
+ Authorization: `Bearer ${session.data.session.token}`,
14
+ },
15
+ });
16
+ };
17
+ }
18
+ //# sourceMappingURL=use-auth-fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-auth-fetch.js","sourceRoot":"","sources":["../../src/hooks/use-auth-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAEtC,OAAO,KAAK,EAAE,GAAW,EAAE,UAAuB,EAAE,EAAE,EAAE;QACtD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QAE1C,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACvC,CAAC;QAED,OAAO,KAAK,CAAC,GAAG,EAAE;YAChB,GAAG,OAAO;YACV,OAAO,EAAE;gBACP,GAAG,OAAO,CAAC,OAAO;gBAClB,aAAa,EAAE,UAAU,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;aACtD;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { JengoAuthClient } from "../client";
2
+ export declare function getAuthClient(authUrl: string): JengoAuthClient;
3
+ export declare function useSession(authUrl: string): {
4
+ data: {
5
+ user: import("better-auth").StripEmptyObjects<{
6
+ id: string;
7
+ createdAt: Date;
8
+ updatedAt: Date;
9
+ email: string;
10
+ emailVerified: boolean;
11
+ name: string;
12
+ image?: string | null | undefined;
13
+ }>;
14
+ session: import("better-auth").StripEmptyObjects<{
15
+ id: string;
16
+ createdAt: Date;
17
+ updatedAt: Date;
18
+ userId: string;
19
+ expiresAt: Date;
20
+ token: string;
21
+ ipAddress?: string | null | undefined;
22
+ userAgent?: string | null | undefined;
23
+ }>;
24
+ } | null;
25
+ isPending: boolean;
26
+ isRefetching: boolean;
27
+ error: import("better-auth/react").BetterFetchError | null;
28
+ refetch: (queryParams?: {
29
+ query?: import("better-auth").SessionQueryParams;
30
+ } | undefined) => Promise<void>;
31
+ };
32
+ //# sourceMappingURL=use-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-session.d.ts","sourceRoot":"","sources":["../../src/hooks/use-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,eAAe,EAAE,MAAM,WAAW,CAAC;AAInE,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAK9D;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;yBAI23C,CAAC;aAAe,CAAC;;EADr7C"}
@@ -0,0 +1,13 @@
1
+ import { createJengoAuthClient } from "../client";
2
+ let clientInstance = null;
3
+ export function getAuthClient(authUrl) {
4
+ if (!clientInstance) {
5
+ clientInstance = createJengoAuthClient({ authUrl });
6
+ }
7
+ return clientInstance;
8
+ }
9
+ export function useSession(authUrl) {
10
+ const client = getAuthClient(authUrl);
11
+ return client.useSession();
12
+ }
13
+ //# sourceMappingURL=use-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-session.js","sourceRoot":"","sources":["../../src/hooks/use-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAmB,MAAM,WAAW,CAAC;AAEnE,IAAI,cAAc,GAA2B,IAAI,CAAC;AAElD,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,qBAAqB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { createJengoAuthClient } from "./client";
2
+ export type { JengoAuthClient } from "./client";
3
+ export { useSession, getAuthClient } from "./hooks/use-session";
4
+ export { useAuthFetch } from "./hooks/use-auth-fetch";
5
+ export { ProtectedRoute } from "./components/protected-route";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { createJengoAuthClient } from "./client";
2
+ export { useSession, getAuthClient } from "./hooks/use-session";
3
+ export { useAuthFetch } from "./hooks/use-auth-fetch";
4
+ export { ProtectedRoute } from "./components/protected-route";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,8 @@
1
+ interface NextAuthMiddlewareConfig {
2
+ authServerUrl: string;
3
+ publicPaths?: string[];
4
+ signInPath?: string;
5
+ }
6
+ export declare function createNextAuthMiddleware(config: NextAuthMiddlewareConfig): (request: any) => Promise<import("next/server").NextResponse<unknown>>;
7
+ export {};
8
+ //# sourceMappingURL=nextjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextjs.d.ts","sourceRoot":"","sources":["../../src/middleware/nextjs.ts"],"names":[],"mappings":"AAAA,UAAU,wBAAwB;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,wBAAwB,IAOtC,SAAS,GAAG,0DA2B9C"}
@@ -0,0 +1,23 @@
1
+ export function createNextAuthMiddleware(config) {
2
+ const { authServerUrl, publicPaths = [], signInPath = "/sign-in", } = config;
3
+ return async function middleware(request) {
4
+ const { NextResponse } = await import("next/server");
5
+ if (publicPaths.some((p) => request.nextUrl.pathname.startsWith(p))) {
6
+ return NextResponse.next();
7
+ }
8
+ const sessionCookie = request.cookies.get("better-auth.session_token");
9
+ if (!sessionCookie) {
10
+ return NextResponse.redirect(new URL(signInPath, request.url));
11
+ }
12
+ const response = await fetch(`${authServerUrl}/api/auth/session`, {
13
+ headers: {
14
+ Cookie: `better-auth.session_token=${sessionCookie.value}`,
15
+ },
16
+ });
17
+ if (!response.ok) {
18
+ return NextResponse.redirect(new URL(signInPath, request.url));
19
+ }
20
+ return NextResponse.next();
21
+ };
22
+ }
23
+ //# sourceMappingURL=nextjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextjs.js","sourceRoot":"","sources":["../../src/middleware/nextjs.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,wBAAwB,CAAC,MAAgC;IACvE,MAAM,EACJ,aAAa,EACb,WAAW,GAAG,EAAE,EAChB,UAAU,GAAG,UAAU,GACxB,GAAG,MAAM,CAAC;IAEX,OAAO,KAAK,UAAU,UAAU,CAAC,OAAY;QAC3C,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;QAErD,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5E,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CACvC,2BAA2B,CAC5B,CAAC;QAEF,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,OAAO,YAAY,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,aAAa,mBAAmB,EAAE;YAChE,OAAO,EAAE;gBACP,MAAM,EAAE,6BAA6B,aAAa,CAAC,KAAK,EAAE;aAC3D;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,OAAO,YAAY,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QACjE,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@jengolabs/auth-react",
3
+ "version": "0.1.0",
4
+ "description": "React SDK for Jengo Auth — hooks, components, and Next.js middleware",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/**/*"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./middleware/nextjs": {
16
+ "types": "./dist/middleware/nextjs.d.ts",
17
+ "default": "./dist/middleware/nextjs.js"
18
+ }
19
+ },
20
+ "dependencies": {
21
+ "better-auth": "^1.2.9"
22
+ },
23
+ "peerDependencies": {
24
+ "react": ">=18.0.0",
25
+ "next": ">=14.0.0"
26
+ },
27
+ "peerDependenciesMeta": {
28
+ "next": {
29
+ "optional": true
30
+ }
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.8.3",
34
+ "@types/node": "^22.15.21",
35
+ "@types/react": "^19.0.0",
36
+ "react": "^19.1.0",
37
+ "next": "^15.0.0"
38
+ },
39
+ "license": "MIT",
40
+ "publishConfig": {
41
+ "registry": "https://registry.npmjs.org",
42
+ "access": "public"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc",
46
+ "dev": "tsc --watch",
47
+ "type-check": "tsc --noEmit",
48
+ "clean": "rm -rf dist"
49
+ }
50
+ }