authmi 1.0.0 → 1.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.
package/dist/next.mjs CHANGED
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  AuthMiClient,
3
3
  AuthMiError,
4
- LocalStorageTokenStorage,
5
- MemoryTokenStorage,
6
4
  ScopeError,
7
5
  __commonJS,
8
6
  __require,
9
7
  __toESM
10
- } from "./chunk-UNKK6FP4.mjs";
8
+ } from "./chunk-EAK7C6YO.mjs";
11
9
 
12
10
  // ../../node_modules/next/dist/shared/lib/i18n/detect-domain-locale.js
13
11
  var require_detect_domain_locale = __commonJS({
@@ -4428,7 +4426,6 @@ var require_server = __commonJS({
4428
4426
 
4429
4427
  // src/next.tsx
4430
4428
  var import_server = __toESM(require_server());
4431
- import { jsx } from "react/jsx-runtime";
4432
4429
  function createAuthMiMiddleware(options) {
4433
4430
  return async function middleware(request) {
4434
4431
  const {
@@ -4446,10 +4443,7 @@ function createAuthMiMiddleware(options) {
4446
4443
  }
4447
4444
  const token = request.cookies.get("authmi_token")?.value || request.headers.get("Authorization")?.replace("Bearer ", "");
4448
4445
  if (!token) {
4449
- if (protectedPaths.some((p) => pathname.startsWith(p))) {
4450
- return import_server.NextResponse.redirect(new URL(loginPath, request.url));
4451
- }
4452
- if (Object.keys(scopedPaths).some((p) => pathname.startsWith(p))) {
4446
+ if (protectedPaths.some((p) => pathname.startsWith(p)) || Object.keys(scopedPaths).some((p) => pathname.startsWith(p))) {
4453
4447
  return import_server.NextResponse.redirect(new URL(loginPath, request.url));
4454
4448
  }
4455
4449
  return import_server.NextResponse.next();
@@ -4481,9 +4475,7 @@ function createAuthMiMiddleware(options) {
4481
4475
  requestHeaders.set("x-user-email", introspectResult.email || "");
4482
4476
  requestHeaders.set("x-user-scopes", JSON.stringify(introspectResult.scopes || []));
4483
4477
  return import_server.NextResponse.next({
4484
- request: {
4485
- headers: requestHeaders
4486
- }
4478
+ request: { headers: requestHeaders }
4487
4479
  });
4488
4480
  } catch (error) {
4489
4481
  console.error("Auth middleware error:", error);
@@ -4494,11 +4486,6 @@ function createAuthMiMiddleware(options) {
4494
4486
  }
4495
4487
  };
4496
4488
  }
4497
- function withScope(Component, _requiredScopes, _config) {
4498
- return function WithScopeWrapper(props) {
4499
- return /* @__PURE__ */ jsx(Component, { ...props });
4500
- };
4501
- }
4502
4489
  async function validateScopes(request, options) {
4503
4490
  const { baseUrl, apiKey, requiredScopes, serviceId } = options;
4504
4491
  const authHeader = request.headers.get("Authorization");
@@ -4507,12 +4494,9 @@ async function validateScopes(request, options) {
4507
4494
  return { valid: false, error: "No token provided", status: 401 };
4508
4495
  }
4509
4496
  const client = new AuthMiClient({ baseUrl, apiKey, serviceId });
4510
- if (!serviceId) {
4511
- return { valid: false, error: "Service ID not configured", status: 500 };
4512
- }
4513
4497
  try {
4514
4498
  const result = await client.introspect({
4515
- serviceId: options.serviceId,
4499
+ serviceId,
4516
4500
  token,
4517
4501
  requiredScopes
4518
4502
  });
@@ -4536,10 +4520,7 @@ async function validateScopes(request, options) {
4536
4520
  export {
4537
4521
  AuthMiClient,
4538
4522
  AuthMiError,
4539
- LocalStorageTokenStorage,
4540
- MemoryTokenStorage,
4541
4523
  ScopeError,
4542
4524
  createAuthMiMiddleware,
4543
- validateScopes,
4544
- withScope
4525
+ validateScopes
4545
4526
  };
package/dist/react.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { b as AuthMiConfig, T as TokenStorage, a as AuthMiClient, U as User, V as ValidationResult } from './client-D6JiIhlU.mjs';
4
- export { A as ApiKey, c as AuthMiError, d as AuthToken, C as CreateApiKeyRequest, e as CreateApiKeyResponse, f as CreateScopeRequest, g as CreateUserRequest, I as IntrospectRequest, h as IntrospectResponse, L as LocalStorageTokenStorage, i as LoginCredentials, M as MemoryTokenStorage, O as OAuthCallbackResult, j as OAuthInitiateResponse, k as OAuthProvider, l as OnboardRequest, m as OnboardResponse, R as RegisterWebhookRequest, S as Scope, n as ScopeError, o as Service, p as UserListResponse, W as Webhook } from './client-D6JiIhlU.mjs';
3
+ import { i as ConfigProvider, h as ClientOptions, G as Setup2FAResult, E as Enable2FAResult, B as BackupCodesResult, C as Challenge2FARequest, f as AuthToken, s as OAuthProvider, c as AuthMiClient, M as User, V as ValidationResult, O as OAuthCallbackResult } from './client-DmZsG2xs.mjs';
4
+ export { A as ApiKey, a as AuditLog, b as AuditLogQuery, d as AuthMiConfig, e as AuthMiError, g as CheckoutResponse, j as CreateApiKeyRequest, k as CreateApiKeyResponse, l as CreateRoleRequest, m as CreateSamlConnectionRequest, n as CreateScopeRequest, o as CreateUserRequest, F as ForgotPasswordRequest, p as IntrospectRequest, q as IntrospectResponse, J as JwksResponse, L as LoginCredentials, r as OAuthInitiateResponse, P as Plan, t as PortalResponse, R as RegisterWebhookRequest, u as ResendVerificationRequest, v as ResetPasswordRequest, w as Role, S as SamlConnection, x as SamlInitiateRequest, y as Scope, z as ScopeError, D as ServiceDetail, H as SignupCredentials, K as Subscription, U as UpdateServiceRequest, N as VerifyEmailRequest, W as Webhook } from './client-DmZsG2xs.mjs';
5
5
 
6
6
  interface AuthMiContextValue {
7
7
  client: AuthMiClient;
@@ -9,54 +9,53 @@ interface AuthMiContextValue {
9
9
  user: User | null;
10
10
  isLoading: boolean;
11
11
  login: (email: string, password: string) => Promise<void>;
12
+ signup: (email: string, password: string, name?: string) => Promise<void>;
12
13
  logout: () => Promise<void>;
13
14
  validate: () => Promise<ValidationResult>;
15
+ setup2fa: () => Promise<Setup2FAResult>;
16
+ enable2fa: (code: string) => Promise<Enable2FAResult>;
17
+ disable2fa: (password: string) => Promise<void>;
18
+ regenerateBackupCodes: () => Promise<BackupCodesResult>;
19
+ challenge2fa: (request: Challenge2FARequest) => Promise<AuthToken>;
20
+ forgotPassword: (email: string) => Promise<{
21
+ message: string;
22
+ }>;
23
+ initiateOAuth: (provider: OAuthProvider, redirectUri: string) => Promise<string>;
24
+ handleOAuthCallback: (url: string | URL) => OAuthCallbackResult | null;
25
+ isOAuthCallback: (url: string | URL) => boolean;
26
+ getMe: () => Promise<User>;
14
27
  }
15
28
  interface AuthMiProviderProps {
16
- config: AuthMiConfig;
17
- tokenStorage?: TokenStorage;
29
+ config: ConfigProvider;
30
+ options?: ClientOptions;
18
31
  children: ReactNode;
19
- /**
20
- * Validate token on mount and periodically
21
- */
22
32
  validateOnMount?: boolean;
23
- /**
24
- * Validation interval in milliseconds (default: 5 minutes)
25
- */
26
33
  validationInterval?: number;
27
34
  }
28
- declare function AuthMiProvider({ config, tokenStorage, children, validateOnMount, validationInterval, }: AuthMiProviderProps): react_jsx_runtime.JSX.Element;
29
- /**
30
- * Access the Auth Mi context
31
- */
35
+ declare function AuthMiProvider({ config, options, children, validateOnMount, validationInterval, }: AuthMiProviderProps): react_jsx_runtime.JSX.Element;
32
36
  declare function useAuthMi(): AuthMiContextValue;
33
- /**
34
- * Get the Auth Mi client instance
35
- */
36
37
  declare function useAuthMiClient(): AuthMiClient;
37
- /**
38
- * Check if user is authenticated
39
- */
40
38
  declare function useIsAuthenticated(): boolean;
41
- /**
42
- * Get current user
43
- */
44
39
  declare function useUser(): User | null;
45
- /**
46
- * Login/logout methods
47
- */
48
40
  declare function useAuthActions(): {
49
41
  login: (email: string, password: string) => Promise<void>;
42
+ signup: (email: string, password: string, name?: string) => Promise<void>;
50
43
  logout: () => Promise<void>;
51
44
  isLoading: boolean;
45
+ forgotPassword: (email: string) => Promise<{
46
+ message: string;
47
+ }>;
48
+ setup2fa: () => Promise<Setup2FAResult>;
49
+ enable2fa: (code: string) => Promise<Enable2FAResult>;
50
+ disable2fa: (password: string) => Promise<void>;
51
+ regenerateBackupCodes: () => Promise<BackupCodesResult>;
52
+ challenge2fa: (request: Challenge2FARequest) => Promise<AuthToken>;
53
+ initiateOAuth: (provider: OAuthProvider, redirectUri: string) => Promise<string>;
52
54
  };
53
55
  interface ProtectedProps {
54
56
  children: ReactNode;
55
57
  fallback?: ReactNode;
56
58
  }
57
- /**
58
- * Component that only renders children when authenticated
59
- */
60
59
  declare function Protected({ children, fallback }: ProtectedProps): react_jsx_runtime.JSX.Element | null;
61
60
  interface LoginFormProps {
62
61
  onSuccess?: () => void;
@@ -65,4 +64,4 @@ interface LoginFormProps {
65
64
  }
66
65
  declare function LoginForm({ onSuccess, onError, className }: LoginFormProps): react_jsx_runtime.JSX.Element;
67
66
 
68
- export { AuthMiClient, AuthMiConfig, AuthMiProvider, LoginForm, Protected, TokenStorage, User, ValidationResult, useAuthActions, useAuthMi, useAuthMiClient, useIsAuthenticated, useUser };
67
+ export { AuthMiClient, AuthMiProvider, AuthToken, BackupCodesResult, Challenge2FARequest, ClientOptions, ConfigProvider, Enable2FAResult, LoginForm, OAuthCallbackResult, OAuthProvider, Protected, Setup2FAResult, User, ValidationResult, useAuthActions, useAuthMi, useAuthMiClient, useIsAuthenticated, useUser };
package/dist/react.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { b as AuthMiConfig, T as TokenStorage, a as AuthMiClient, U as User, V as ValidationResult } from './client-D6JiIhlU.js';
4
- export { A as ApiKey, c as AuthMiError, d as AuthToken, C as CreateApiKeyRequest, e as CreateApiKeyResponse, f as CreateScopeRequest, g as CreateUserRequest, I as IntrospectRequest, h as IntrospectResponse, L as LocalStorageTokenStorage, i as LoginCredentials, M as MemoryTokenStorage, O as OAuthCallbackResult, j as OAuthInitiateResponse, k as OAuthProvider, l as OnboardRequest, m as OnboardResponse, R as RegisterWebhookRequest, S as Scope, n as ScopeError, o as Service, p as UserListResponse, W as Webhook } from './client-D6JiIhlU.js';
3
+ import { i as ConfigProvider, h as ClientOptions, G as Setup2FAResult, E as Enable2FAResult, B as BackupCodesResult, C as Challenge2FARequest, f as AuthToken, s as OAuthProvider, c as AuthMiClient, M as User, V as ValidationResult, O as OAuthCallbackResult } from './client-DmZsG2xs.js';
4
+ export { A as ApiKey, a as AuditLog, b as AuditLogQuery, d as AuthMiConfig, e as AuthMiError, g as CheckoutResponse, j as CreateApiKeyRequest, k as CreateApiKeyResponse, l as CreateRoleRequest, m as CreateSamlConnectionRequest, n as CreateScopeRequest, o as CreateUserRequest, F as ForgotPasswordRequest, p as IntrospectRequest, q as IntrospectResponse, J as JwksResponse, L as LoginCredentials, r as OAuthInitiateResponse, P as Plan, t as PortalResponse, R as RegisterWebhookRequest, u as ResendVerificationRequest, v as ResetPasswordRequest, w as Role, S as SamlConnection, x as SamlInitiateRequest, y as Scope, z as ScopeError, D as ServiceDetail, H as SignupCredentials, K as Subscription, U as UpdateServiceRequest, N as VerifyEmailRequest, W as Webhook } from './client-DmZsG2xs.js';
5
5
 
6
6
  interface AuthMiContextValue {
7
7
  client: AuthMiClient;
@@ -9,54 +9,53 @@ interface AuthMiContextValue {
9
9
  user: User | null;
10
10
  isLoading: boolean;
11
11
  login: (email: string, password: string) => Promise<void>;
12
+ signup: (email: string, password: string, name?: string) => Promise<void>;
12
13
  logout: () => Promise<void>;
13
14
  validate: () => Promise<ValidationResult>;
15
+ setup2fa: () => Promise<Setup2FAResult>;
16
+ enable2fa: (code: string) => Promise<Enable2FAResult>;
17
+ disable2fa: (password: string) => Promise<void>;
18
+ regenerateBackupCodes: () => Promise<BackupCodesResult>;
19
+ challenge2fa: (request: Challenge2FARequest) => Promise<AuthToken>;
20
+ forgotPassword: (email: string) => Promise<{
21
+ message: string;
22
+ }>;
23
+ initiateOAuth: (provider: OAuthProvider, redirectUri: string) => Promise<string>;
24
+ handleOAuthCallback: (url: string | URL) => OAuthCallbackResult | null;
25
+ isOAuthCallback: (url: string | URL) => boolean;
26
+ getMe: () => Promise<User>;
14
27
  }
15
28
  interface AuthMiProviderProps {
16
- config: AuthMiConfig;
17
- tokenStorage?: TokenStorage;
29
+ config: ConfigProvider;
30
+ options?: ClientOptions;
18
31
  children: ReactNode;
19
- /**
20
- * Validate token on mount and periodically
21
- */
22
32
  validateOnMount?: boolean;
23
- /**
24
- * Validation interval in milliseconds (default: 5 minutes)
25
- */
26
33
  validationInterval?: number;
27
34
  }
28
- declare function AuthMiProvider({ config, tokenStorage, children, validateOnMount, validationInterval, }: AuthMiProviderProps): react_jsx_runtime.JSX.Element;
29
- /**
30
- * Access the Auth Mi context
31
- */
35
+ declare function AuthMiProvider({ config, options, children, validateOnMount, validationInterval, }: AuthMiProviderProps): react_jsx_runtime.JSX.Element;
32
36
  declare function useAuthMi(): AuthMiContextValue;
33
- /**
34
- * Get the Auth Mi client instance
35
- */
36
37
  declare function useAuthMiClient(): AuthMiClient;
37
- /**
38
- * Check if user is authenticated
39
- */
40
38
  declare function useIsAuthenticated(): boolean;
41
- /**
42
- * Get current user
43
- */
44
39
  declare function useUser(): User | null;
45
- /**
46
- * Login/logout methods
47
- */
48
40
  declare function useAuthActions(): {
49
41
  login: (email: string, password: string) => Promise<void>;
42
+ signup: (email: string, password: string, name?: string) => Promise<void>;
50
43
  logout: () => Promise<void>;
51
44
  isLoading: boolean;
45
+ forgotPassword: (email: string) => Promise<{
46
+ message: string;
47
+ }>;
48
+ setup2fa: () => Promise<Setup2FAResult>;
49
+ enable2fa: (code: string) => Promise<Enable2FAResult>;
50
+ disable2fa: (password: string) => Promise<void>;
51
+ regenerateBackupCodes: () => Promise<BackupCodesResult>;
52
+ challenge2fa: (request: Challenge2FARequest) => Promise<AuthToken>;
53
+ initiateOAuth: (provider: OAuthProvider, redirectUri: string) => Promise<string>;
52
54
  };
53
55
  interface ProtectedProps {
54
56
  children: ReactNode;
55
57
  fallback?: ReactNode;
56
58
  }
57
- /**
58
- * Component that only renders children when authenticated
59
- */
60
59
  declare function Protected({ children, fallback }: ProtectedProps): react_jsx_runtime.JSX.Element | null;
61
60
  interface LoginFormProps {
62
61
  onSuccess?: () => void;
@@ -65,4 +64,4 @@ interface LoginFormProps {
65
64
  }
66
65
  declare function LoginForm({ onSuccess, onError, className }: LoginFormProps): react_jsx_runtime.JSX.Element;
67
66
 
68
- export { AuthMiClient, AuthMiConfig, AuthMiProvider, LoginForm, Protected, TokenStorage, User, ValidationResult, useAuthActions, useAuthMi, useAuthMiClient, useIsAuthenticated, useUser };
67
+ export { AuthMiClient, AuthMiProvider, AuthToken, BackupCodesResult, Challenge2FARequest, ClientOptions, ConfigProvider, Enable2FAResult, LoginForm, OAuthCallbackResult, OAuthProvider, Protected, Setup2FAResult, User, ValidationResult, useAuthActions, useAuthMi, useAuthMiClient, useIsAuthenticated, useUser };