@greatapps/greatauth-ui 0.1.2 → 0.1.4

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/index.d.ts CHANGED
@@ -3,12 +3,13 @@ import { ReactNode, ComponentType } from 'react';
3
3
  import * as nanostores from 'nanostores';
4
4
  import * as _better_fetch_fetch from '@better-fetch/fetch';
5
5
  import * as better_auth from 'better-auth';
6
- import { NextRequest, NextResponse } from 'next/server';
6
+ export { AuthMiddlewareConfig, authMiddlewareConfig, createAuthMiddleware } from './middleware.js';
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
8
  import * as class_variance_authority_types from 'class-variance-authority/types';
9
9
  import { VariantProps } from 'class-variance-authority';
10
10
  import { Tooltip } from 'radix-ui';
11
11
  import { ClassValue } from 'clsx';
12
+ import 'next/server';
12
13
 
13
14
  interface AppShellConfig {
14
15
  appName: string;
@@ -1042,15 +1043,6 @@ declare const signOut: <FetchOptions extends better_auth.ClientFetchOption<never
1042
1043
  message?: string | undefined;
1043
1044
  }, FetchOptions["throw"] extends true ? true : false>>;
1044
1045
 
1045
- interface AuthMiddlewareConfig {
1046
- publicPaths: string[];
1047
- preserveSearchParams?: boolean;
1048
- }
1049
- declare function createAuthMiddleware(config: AuthMiddlewareConfig): (request: NextRequest) => NextResponse<unknown>;
1050
- declare const authMiddlewareConfig: {
1051
- matcher: string[];
1052
- };
1053
-
1054
1046
  interface JwtClaimsConfig {
1055
1047
  [jwtClaimName: string]: string;
1056
1048
  }
@@ -1115,4 +1107,4 @@ declare function SidebarInset({ className, ...props }: React.ComponentProps<"mai
1115
1107
 
1116
1108
  declare function cn(...inputs: ClassValue[]): string;
1117
1109
 
1118
- export { AppHeader, AppShell, type AppShellConfig, AppSidebar, type AuthMiddlewareConfig, type HeaderConfig, LoginForm, type LoginFormConfig, type MenuGroup, type MenuItem, SidebarInset, SidebarProvider, SidebarTrigger, ThemeToggle, TooltipProvider, authClient, authMiddlewareConfig, cn, createAuthMiddleware, createUseAuth, signIn, signOut, signUp, useSession, useSidebar };
1110
+ export { AppHeader, AppShell, type AppShellConfig, AppSidebar, type HeaderConfig, LoginForm, type LoginFormConfig, type MenuGroup, type MenuItem, SidebarInset, SidebarProvider, SidebarTrigger, ThemeToggle, TooltipProvider, authClient, cn, createUseAuth, signIn, signOut, signUp, useSession, useSidebar };
@@ -0,0 +1,12 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+
3
+ interface AuthMiddlewareConfig {
4
+ publicPaths: string[];
5
+ preserveSearchParams?: boolean;
6
+ }
7
+ declare function createAuthMiddleware(config: AuthMiddlewareConfig): (request: NextRequest) => NextResponse<unknown>;
8
+ declare const authMiddlewareConfig: {
9
+ matcher: string[];
10
+ };
11
+
12
+ export { type AuthMiddlewareConfig, authMiddlewareConfig, createAuthMiddleware };
@@ -0,0 +1,27 @@
1
+ // src/auth/middleware.ts
2
+ import { NextResponse } from "next/server";
3
+ function createAuthMiddleware(config) {
4
+ const { publicPaths, preserveSearchParams = false } = config;
5
+ return function middleware(request) {
6
+ const { pathname, search } = request.nextUrl;
7
+ if (publicPaths.some((path) => pathname.startsWith(path))) {
8
+ return NextResponse.next();
9
+ }
10
+ const sessionToken = request.cookies.get("better-auth.session_token")?.value || request.cookies.get("__Secure-better-auth.session_token")?.value;
11
+ if (!sessionToken) {
12
+ const callbackUrl = preserveSearchParams ? pathname + search : pathname;
13
+ const loginUrl = new URL("/login", request.url);
14
+ loginUrl.searchParams.set("callbackUrl", callbackUrl);
15
+ return NextResponse.redirect(loginUrl);
16
+ }
17
+ return NextResponse.next();
18
+ };
19
+ }
20
+ var authMiddlewareConfig = {
21
+ matcher: ["/((?!_next/static|_next/image|favicon.ico|api/auth).*)"]
22
+ };
23
+ export {
24
+ authMiddlewareConfig,
25
+ createAuthMiddleware
26
+ };
27
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auth/middleware.ts"],"sourcesContent":["import { NextResponse, type NextRequest } from \"next/server\";\n\nexport interface AuthMiddlewareConfig {\n publicPaths: string[];\n preserveSearchParams?: boolean;\n}\n\nexport function createAuthMiddleware(config: AuthMiddlewareConfig) {\n const { publicPaths, preserveSearchParams = false } = config;\n\n return function middleware(request: NextRequest) {\n const { pathname, search } = request.nextUrl;\n\n if (publicPaths.some((path) => pathname.startsWith(path))) {\n return NextResponse.next();\n }\n\n const sessionToken =\n request.cookies.get(\"better-auth.session_token\")?.value ||\n request.cookies.get(\"__Secure-better-auth.session_token\")?.value;\n\n if (!sessionToken) {\n const callbackUrl = preserveSearchParams\n ? pathname + search\n : pathname;\n\n const loginUrl = new URL(\"/login\", request.url);\n loginUrl.searchParams.set(\"callbackUrl\", callbackUrl);\n return NextResponse.redirect(loginUrl);\n }\n\n return NextResponse.next();\n };\n}\n\nexport const authMiddlewareConfig = {\n matcher: [\"/((?!_next/static|_next/image|favicon.ico|api/auth).*)\"],\n};\n"],"mappings":";AAAA,SAAS,oBAAsC;AAOxC,SAAS,qBAAqB,QAA8B;AACjE,QAAM,EAAE,aAAa,uBAAuB,MAAM,IAAI;AAEtD,SAAO,SAAS,WAAW,SAAsB;AAC/C,UAAM,EAAE,UAAU,OAAO,IAAI,QAAQ;AAErC,QAAI,YAAY,KAAK,CAAC,SAAS,SAAS,WAAW,IAAI,CAAC,GAAG;AACzD,aAAO,aAAa,KAAK;AAAA,IAC3B;AAEA,UAAM,eACJ,QAAQ,QAAQ,IAAI,2BAA2B,GAAG,SAClD,QAAQ,QAAQ,IAAI,oCAAoC,GAAG;AAE7D,QAAI,CAAC,cAAc;AACjB,YAAM,cAAc,uBAChB,WAAW,SACX;AAEJ,YAAM,WAAW,IAAI,IAAI,UAAU,QAAQ,GAAG;AAC9C,eAAS,aAAa,IAAI,eAAe,WAAW;AACpD,aAAO,aAAa,SAAS,QAAQ;AAAA,IACvC;AAEA,WAAO,aAAa,KAAK;AAAA,EAC3B;AACF;AAEO,IAAM,uBAAuB;AAAA,EAClC,SAAS,CAAC,wDAAwD;AACpE;","names":[]}
package/package.json CHANGED
@@ -1,16 +1,25 @@
1
1
  {
2
2
  "name": "@greatapps/greatauth-ui",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
- "import": "./dist/index.js"
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./middleware": {
14
+ "types": "./dist/middleware.d.ts",
15
+ "import": "./dist/middleware.js",
16
+ "default": "./dist/middleware.js"
11
17
  }
12
18
  },
13
- "files": ["dist", "src"],
19
+ "files": [
20
+ "dist",
21
+ "src"
22
+ ],
14
23
  "scripts": {
15
24
  "build": "tsup",
16
25
  "dev": "tsup --watch"
@@ -0,0 +1,2 @@
1
+ export { createAuthMiddleware, authMiddlewareConfig } from "./auth/middleware";
2
+ export type { AuthMiddlewareConfig } from "./auth/middleware";