@artatol-acp/auth-nextjs 0.1.1 → 0.3.1

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/README.md CHANGED
@@ -10,6 +10,19 @@ npm install @artatol-acp/auth-nextjs
10
10
  pnpm add @artatol-acp/auth-nextjs
11
11
  ```
12
12
 
13
+ ## Prerequisites
14
+
15
+ Before using this SDK, you need to obtain from the ACP AUTH service:
16
+
17
+ 1. **API Key** (required) - Contact your system administrator
18
+ 2. **Base URL** (required) - The auth service URL (e.g., `https://sso.artatol.net`)
19
+ 3. **JWT Public Key** (optional) - Only needed for local JWT verification with `getUser()`. Download it from:
20
+ ```bash
21
+ curl https://sso.artatol.net/public-key > public.pem
22
+ ```
23
+
24
+ **Note:** Without the public key, you can still use all auth operations (login, register, logout, 2FA, password reset, etc.), but you must use the `me()` function instead of `getUser()` for user verification, which makes an API call to the auth service.
25
+
13
26
  ## Setup
14
27
 
15
28
  ### 1. Initialize Server-side
@@ -24,6 +37,7 @@ const publicKey = readFileSync('./keys/public.pem', 'utf-8');
24
37
 
25
38
  export const auth = initACPAuth({
26
39
  baseUrl: process.env.ACP_AUTH_URL || 'https://sso.artatol.com',
40
+ apiKey: process.env.ACP_AUTH_API_KEY!,
27
41
  jwtPublicKey: publicKey,
28
42
  });
29
43
  ```
@@ -118,7 +132,8 @@ export async function registerAction(formData: FormData) {
118
132
  const password = formData.get('password') as string;
119
133
 
120
134
  await register(email, password);
121
- redirect('/login');
135
+ // User will receive verification email
136
+ redirect('/check-email');
122
137
  }
123
138
 
124
139
  export async function logoutAction() {
@@ -171,6 +186,7 @@ import { ACPAuthClient } from '@artatol-acp/auth-nextjs/server';
171
186
 
172
187
  const client = new ACPAuthClient({
173
188
  baseUrl: process.env.ACP_AUTH_URL!,
189
+ apiKey: process.env.ACP_AUTH_API_KEY!,
174
190
  });
175
191
 
176
192
  export async function POST(request: Request) {
@@ -182,10 +198,125 @@ export async function POST(request: Request) {
182
198
  }
183
199
  ```
184
200
 
201
+ ## Password Requirements
202
+
203
+ Passwords must meet the following requirements:
204
+ - Minimum 10 characters
205
+ - At least one lowercase letter (a-z)
206
+ - At least one uppercase letter (A-Z)
207
+ - At least one number (0-9)
208
+
209
+ ```typescript
210
+ // Example validation on the client side
211
+ function validatePassword(password: string): string[] {
212
+ const errors: string[] = [];
213
+
214
+ if (password.length < 10) {
215
+ errors.push('Password must be at least 10 characters');
216
+ }
217
+ if (!/[a-z]/.test(password)) {
218
+ errors.push('Password must contain at least one lowercase letter');
219
+ }
220
+ if (!/[A-Z]/.test(password)) {
221
+ errors.push('Password must contain at least one uppercase letter');
222
+ }
223
+ if (!/[0-9]/.test(password)) {
224
+ errors.push('Password must contain at least one number');
225
+ }
226
+
227
+ return errors;
228
+ }
229
+ ```
230
+
231
+ ## Email Verification
232
+
233
+ After registration, users must verify their email address before they can log in. The auth service automatically sends a verification email upon registration.
234
+
235
+ ### Verification Flow
236
+
237
+ 1. User registers → receives verification email
238
+ 2. User clicks link in email → email is verified
239
+ 3. User can now log in
240
+
241
+ ### Server Actions
242
+
243
+ ```typescript
244
+ 'use server';
245
+
246
+ import { verifyEmail, resendVerificationEmail } from '@artatol-acp/auth-nextjs/server';
247
+ import { redirect } from 'next/navigation';
248
+
249
+ export async function verifyEmailAction(token: string) {
250
+ try {
251
+ await verifyEmail(token);
252
+ redirect('/login?verified=true');
253
+ } catch (error) {
254
+ redirect('/verification-error');
255
+ }
256
+ }
257
+
258
+ export async function resendVerificationAction(email: string) {
259
+ await resendVerificationEmail(email);
260
+ // Always succeeds to prevent email enumeration
261
+ return { message: 'If the email exists, a verification link has been sent' };
262
+ }
263
+ ```
264
+
265
+ ### Client Component Example
266
+
267
+ ```typescript
268
+ 'use client';
269
+
270
+ import { useAuth } from '@artatol-acp/auth-nextjs/client';
271
+
272
+ export function ResendVerificationButton({ email }: { email: string }) {
273
+ const { resendVerification } = useAuth();
274
+ const [sent, setSent] = useState(false);
275
+
276
+ const handleResend = async () => {
277
+ await resendVerification(email);
278
+ setSent(true);
279
+ };
280
+
281
+ return (
282
+ <button onClick={handleResend} disabled={sent}>
283
+ {sent ? 'Email Sent' : 'Resend Verification Email'}
284
+ </button>
285
+ );
286
+ }
287
+ ```
288
+
289
+ ### Handling Unverified Users
290
+
291
+ When an unverified user tries to log in, they will receive an error:
292
+
293
+ ```typescript
294
+ export async function loginAction(formData: FormData) {
295
+ const email = formData.get('email') as string;
296
+ const password = formData.get('password') as string;
297
+
298
+ try {
299
+ const result = await login(email, password);
300
+
301
+ if ('requiresTwoFactor' in result) {
302
+ return { requires2FA: true, tempToken: result.tempToken };
303
+ }
304
+
305
+ redirect('/dashboard');
306
+ } catch (error: any) {
307
+ if (error.message?.includes('Email not verified')) {
308
+ return { error: 'Please verify your email before logging in' };
309
+ }
310
+ throw error;
311
+ }
312
+ }
313
+ ```
314
+
185
315
  ## Environment Variables
186
316
 
187
317
  ```env
188
318
  ACP_AUTH_URL=https://sso.artatol.com
319
+ ACP_AUTH_API_KEY=your-api-key-here
189
320
  NEXT_PUBLIC_ACP_AUTH_URL=https://sso.artatol.com
190
321
  ```
191
322
 
@@ -200,7 +331,9 @@ NEXT_PUBLIC_ACP_AUTH_URL=https://sso.artatol.com
200
331
  - `refreshAccessToken()` - Refresh access token using refresh token cookie
201
332
  - `login(email, password)` - Login user
202
333
  - `logout()` - Logout user
203
- - `register(email, password)` - Register new user
334
+ - `register(email, password)` - Register new user (sends verification email)
335
+ - `verifyEmail(token)` - Verify user's email address
336
+ - `resendVerificationEmail(email)` - Resend verification email
204
337
 
205
338
  ### Client Hooks
206
339
 
@@ -210,6 +343,148 @@ NEXT_PUBLIC_ACP_AUTH_URL=https://sso.artatol.com
210
343
 
211
344
  - `createACPAuthMiddleware(options)` - Create middleware for route protection
212
345
 
346
+ ## 2FA (Two-Factor Authentication)
347
+
348
+ ### Setup 2FA
349
+
350
+ ```typescript
351
+ 'use server';
352
+
353
+ import { ACPAuthClient } from '@artatol-acp/auth-nextjs/server';
354
+
355
+ export async function setup2FAAction(password: string) {
356
+ const client = new ACPAuthClient({
357
+ baseUrl: process.env.ACP_AUTH_URL!,
358
+ apiKey: process.env.ACP_AUTH_API_KEY!,
359
+ });
360
+
361
+ const accessToken = // ... get from session/cookie
362
+
363
+ const { secret, qrCodeUrl, recoveryCodes } = await client.setup2FA(
364
+ { password },
365
+ accessToken
366
+ );
367
+
368
+ return { qrCodeUrl, recoveryCodes };
369
+ }
370
+ ```
371
+
372
+ ### Verify 2FA Setup
373
+
374
+ ```typescript
375
+ 'use server';
376
+
377
+ export async function verify2FAAction(code: string) {
378
+ const client = new ACPAuthClient({
379
+ baseUrl: process.env.ACP_AUTH_URL!,
380
+ apiKey: process.env.ACP_AUTH_API_KEY!,
381
+ });
382
+
383
+ const accessToken = // ... get from session/cookie
384
+
385
+ await client.verify2FA({ code }, accessToken);
386
+ }
387
+ ```
388
+
389
+ ### Complete 2FA Login Flow
390
+
391
+ ```typescript
392
+ 'use server';
393
+
394
+ import { login } from '@artatol-acp/auth-nextjs/server';
395
+
396
+ export async function loginAction(email: string, password: string) {
397
+ const result = await login(email, password);
398
+
399
+ if ('requiresTwoFactor' in result) {
400
+ // User has 2FA enabled
401
+ return {
402
+ requires2FA: true,
403
+ tempToken: result.tempToken,
404
+ };
405
+ }
406
+
407
+ // Regular login successful
408
+ return { success: true };
409
+ }
410
+
411
+ export async function complete2FALogin(tempToken: string, code: string) {
412
+ const client = new ACPAuthClient({
413
+ baseUrl: process.env.ACP_AUTH_URL!,
414
+ apiKey: process.env.ACP_AUTH_API_KEY!,
415
+ });
416
+
417
+ const result = await client.verify2FALogin({ tempToken, code });
418
+ // Set cookies, etc.
419
+ return result;
420
+ }
421
+ ```
422
+
423
+ ### Disable 2FA
424
+
425
+ ```typescript
426
+ 'use server';
427
+
428
+ export async function disable2FAAction(password: string, code: string) {
429
+ const client = new ACPAuthClient({
430
+ baseUrl: process.env.ACP_AUTH_URL!,
431
+ apiKey: process.env.ACP_AUTH_API_KEY!,
432
+ });
433
+
434
+ const accessToken = // ... get from session/cookie
435
+
436
+ await client.disable2FA({ password, code }, accessToken);
437
+ }
438
+ ```
439
+
440
+ ## Health Check
441
+
442
+ To check if the auth service is available:
443
+
444
+ ```typescript
445
+ import { ACPAuthClient } from '@artatol-acp/auth-nextjs/server';
446
+
447
+ const client = new ACPAuthClient({
448
+ baseUrl: process.env.ACP_AUTH_URL!,
449
+ apiKey: process.env.ACP_AUTH_API_KEY!,
450
+ });
451
+
452
+ const health = await client.health();
453
+ console.log(health); // { status: 'ok', timestamp: '...' }
454
+ ```
455
+
456
+ ## Error Handling
457
+
458
+ ```typescript
459
+ import { ACPAuthError } from '@artatol-acp/auth-js';
460
+
461
+ try {
462
+ await login(email, password);
463
+ } catch (error) {
464
+ if (error instanceof ACPAuthError) {
465
+ console.error('Auth error:', error.message);
466
+ console.error('Status code:', error.statusCode);
467
+
468
+ if (error.statusCode === 401) {
469
+ // Invalid credentials
470
+ } else if (error.statusCode === 429) {
471
+ // Rate limited
472
+ }
473
+ } else {
474
+ console.error('Unexpected error:', error);
475
+ }
476
+ }
477
+ ```
478
+
479
+ ### Common Error Codes
480
+
481
+ | Status Code | Meaning |
482
+ |-------------|---------|
483
+ | 401 | Unauthorized (invalid credentials or token) |
484
+ | 403 | Forbidden (email not verified, account locked) |
485
+ | 429 | Too Many Requests (rate limited) |
486
+ | 500 | Internal Server Error |
487
+
213
488
  ## License
214
489
 
215
490
  MIT
@@ -1,4 +1,4 @@
1
- import type { User } from '@artatol-acp/auth-js';
1
+ import { type User } from '@artatol-acp/auth-js';
2
2
  import { type ReactNode } from 'react';
3
3
  export type ACPAuthContextValue = {
4
4
  user: User | null;
@@ -6,6 +6,7 @@ export type ACPAuthContextValue = {
6
6
  login: (email: string, password: string) => Promise<void>;
7
7
  logout: () => Promise<void>;
8
8
  refresh: () => Promise<void>;
9
+ resendVerification: (email: string) => Promise<void>;
9
10
  };
10
11
  export type ACPAuthProviderProps = {
11
12
  children: ReactNode;
@@ -15,3 +16,4 @@ export declare function ACPAuthProvider({ children, baseUrl }: ACPAuthProviderPr
15
16
  export declare function useAuth(): ACPAuthContextValue;
16
17
  export { ACPAuthClient } from '@artatol-acp/auth-js';
17
18
  export type * from '@artatol-acp/auth-js';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAkD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtD,CAAC;AAIF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,oBAAoB,2CA8C1E;AAED,wBAAgB,OAAO,IAAI,mBAAmB,CAM7C;AAGD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,mBAAmB,sBAAsB,CAAC"}
@@ -6,7 +6,7 @@ const ACPAuthContext = createContext(null);
6
6
  export function ACPAuthProvider({ children, baseUrl }) {
7
7
  const [user, setUser] = useState(null);
8
8
  const [isLoading, setIsLoading] = useState(true);
9
- const [client] = useState(() => new ACPAuthClient({ baseUrl }));
9
+ const [client] = useState(() => new ACPAuthClient({ baseUrl, apiKey: '' }));
10
10
  const refresh = async () => {
11
11
  try {
12
12
  await client.refresh();
@@ -30,11 +30,14 @@ export function ACPAuthProvider({ children, baseUrl }) {
30
30
  await client.logout();
31
31
  setUser(null);
32
32
  };
33
+ const resendVerification = async (email) => {
34
+ await client.resendVerificationEmail({ email });
35
+ };
33
36
  useEffect(() => {
34
37
  // Try to restore session on mount
35
38
  refresh().finally(() => setIsLoading(false));
36
39
  }, []);
37
- return (<ACPAuthContext.Provider value={{ user, isLoading, login, logout, refresh }}>
40
+ return (<ACPAuthContext.Provider value={{ user, isLoading, login, logout, refresh, resendVerification }}>
38
41
  {children}
39
42
  </ACPAuthContext.Provider>);
40
43
  }
@@ -47,3 +50,4 @@ export function useAuth() {
47
50
  }
48
51
  // Re-export client for direct use
49
52
  export { ACPAuthClient } from '@artatol-acp/auth-js';
53
+ //# sourceMappingURL=index.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.jsx","sourceRoot":"","sources":["../../src/client/index.tsx"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,YAAY,CAAC;AAEb,OAAO,EAAE,aAAa,EAAa,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAkB,MAAM,OAAO,CAAC;AAWvF,MAAM,cAAc,GAAG,aAAa,CAA6B,IAAI,CAAC,CAAC;AAOvE,MAAM,UAAU,eAAe,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAwB;IACzE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAc,IAAI,CAAC,CAAC;IACpD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjD,MAAM,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,GA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E,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC,CAC9F;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,cAAc,CAAC,QAAQ,CAAC,CAC3B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,OAAO;IACrB,MAAM,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,kCAAkC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './server/index.js';
2
- export * from './client/index.js';
3
- export * from './middleware.js';
1
+ export { ACPAuthClient } from '@artatol-acp/auth-js';
2
+ export type * from '@artatol-acp/auth-js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,mBAAmB,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './server/index.js';
2
- export * from './client/index.js';
3
- export * from './middleware.js';
1
+ // This is the main entry point, but most users will import from /server, /client, or /middleware
2
+ export { ACPAuthClient } from '@artatol-acp/auth-js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
@@ -5,3 +5,4 @@ export type ACPAuthMiddlewareOptions = {
5
5
  loginPath?: string;
6
6
  };
7
7
  export declare function createACPAuthMiddleware(options: ACPAuthMiddlewareOptions): (request: NextRequest) => Promise<NextResponse<unknown>>;
8
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGxD,MAAM,MAAM,wBAAwB,GAAG;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAIF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,IAO/B,SAAS,WAAW,oCAuC7D"}
@@ -6,7 +6,7 @@ export function createACPAuthMiddleware(options) {
6
6
  return async function acpAuthMiddleware(request) {
7
7
  const { pathname } = request.nextUrl;
8
8
  // Allow public paths
9
- if (publicPaths.some(path => pathname.startsWith(path))) {
9
+ if (publicPaths.some((path) => pathname.startsWith(path))) {
10
10
  return NextResponse.next();
11
11
  }
12
12
  // Check for access token
@@ -38,3 +38,4 @@ export function createACPAuthMiddleware(options) {
38
38
  }
39
39
  };
40
40
  }
41
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAgB,MAAM,MAAM,CAAC;AAQ3D,IAAI,SAAS,GAAmB,IAAI,CAAC;AAErC,MAAM,UAAU,uBAAuB,CAAC,OAAiC;IACvE,MAAM,EACJ,YAAY,EACZ,WAAW,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,CAAC,EAC5E,SAAS,GAAG,QAAQ,GACrB,GAAG,OAAO,CAAC;IAEZ,OAAO,KAAK,UAAU,iBAAiB,CAAC,OA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,QAAQ,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { ACPAuthClient, type User, type LoginResult } from '@artatol-acp/auth-js';
2
2
  export type ACPAuthServerOptions = {
3
3
  baseUrl: string;
4
+ apiKey: string;
4
5
  jwtPublicKey: string;
5
6
  };
6
7
  export declare function initACPAuth(options: ACPAuthServerOptions): ACPAuthClient;
@@ -10,6 +11,13 @@ export declare function refreshAccessToken(): Promise<string | null>;
10
11
  export declare function login(email: string, password: string): Promise<LoginResult>;
11
12
  export declare function logout(): Promise<void>;
12
13
  export declare function register(email: string, password: string): Promise<User>;
14
+ export declare function verifyEmail(token: string): Promise<{
15
+ message: string;
16
+ }>;
17
+ export declare function resendVerificationEmail(email: string): Promise<{
18
+ message: string;
19
+ }>;
13
20
  export declare function me(): Promise<User | null>;
14
21
  export { ACPAuthClient } from '@artatol-acp/auth-js';
15
22
  export type * from '@artatol-acp/auth-js';
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGlF,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAMF,wBAAgB,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAOxE;AAqBD,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAepE;AAED,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAapD;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoBjE;AAED,wBAAsB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAiBjF;AAED,wBAAsB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAW5C;AAED,wBAAsB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG7E;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAG7E;AAED,wBAAsB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAGzF;AAED,wBAAsB,EAAE,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAe/C;AAGD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,mBAAmB,sBAAsB,CAAC"}
@@ -6,7 +6,10 @@ let publicKey = null;
6
6
  let config = null;
7
7
  export function initACPAuth(options) {
8
8
  config = options;
9
- authClient = new ACPAuthClient({ baseUrl: options.baseUrl });
9
+ authClient = new ACPAuthClient({
10
+ baseUrl: options.baseUrl,
11
+ apiKey: options.apiKey,
12
+ });
10
13
  return authClient;
11
14
  }
12
15
  async function getPublicKey() {
@@ -103,6 +106,14 @@ export async function register(email, password) {
103
106
  const client = getClient();
104
107
  return await client.register({ email, password });
105
108
  }
109
+ export async function verifyEmail(token) {
110
+ const client = getClient();
111
+ return await client.verifyEmail({ token });
112
+ }
113
+ export async function resendVerificationEmail(email) {
114
+ const client = getClient();
115
+ return await client.resendVerificationEmail({ email });
116
+ }
106
117
  export async function me() {
107
118
  const cookieStore = await cookies();
108
119
  const accessToken = cookieStore.get('access_token')?.value;
@@ -119,3 +130,4 @@ export async function me() {
119
130
  }
120
131
  // Re-export client for direct use if needed
121
132
  export { ACPAuthClient } from '@artatol-acp/auth-js';
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAA+B,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,UAAU,EAAgB,MAAM,MAAM,CAAC;AAQ3D,IAAI,UAAU,GAAyB,IAAI,CAAC;AAC5C,IAAI,SAAS,GAAmB,IAAI,CAAC;AACrC,IAAI,MAAM,GAAgC,IAAI,CAAC;AAE/C,MAAM,UAAU,WAAW,CAAC,OAA6B;IACvD,MAAM,GAAG,OAAO,CAAC;IACjB,UAAU,GAAG,IAAI,aAAa,CAAC;QAC7B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,KAAK,UAAU,YAAY;IACzB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,SAAS;IAChB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,KAAa;IACnD,MAAM,GAAG,GAAG,MAAM,YAAY,EAAE,CAAC;IAEjC,IAAI,CAAC;QACH,MAAM,EAAE,OAAO,EAAE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CAAC,KAAK,UAAU,WAAW,CAAC,KAAa;IAC7C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,OAAO,MAAM,MAAM,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,KAAa;IACzD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,OAAO,MAAM,MAAM,CAAC,uBAAuB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,EAAE;IACtB,MAAM,WAAW,GAAG,MAAM,OAAO,EAAE,CAAC;IACpC,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,KAAK,CAAC;IAE3D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,4CAA4C;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@artatol-acp/auth-nextjs",
3
- "version": "0.1.1",
4
- "description": "Next.js SDK for Artatol Cloud Platform Authentication",
3
+ "version": "0.3.1",
4
+ "description": "Next.js SDK for Artatol Cloud Platform Authentication with support for App Router, Server Actions, and Middleware",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
- "module": "./dist/index.js",
8
7
  "types": "./dist/index.d.ts",
9
8
  "exports": {
10
9
  ".": {
@@ -16,7 +15,7 @@
16
15
  "types": "./dist/server/index.d.ts"
17
16
  },
18
17
  "./client": {
19
- "import": "./dist/client/index.js",
18
+ "import": "./dist/client/index.jsx",
20
19
  "types": "./dist/client/index.d.ts"
21
20
  },
22
21
  "./middleware": {
@@ -27,39 +26,34 @@
27
26
  "files": [
28
27
  "dist"
29
28
  ],
30
- "scripts": {
31
- "build": "tsc",
32
- "dev": "tsc --watch",
33
- "typecheck": "tsc --noEmit"
34
- },
35
29
  "keywords": [
36
30
  "acp",
37
31
  "auth",
38
- "authentication",
39
- "artatol",
40
- "jwt",
41
- "2fa",
42
32
  "nextjs",
43
- "next.js"
33
+ "next",
34
+ "authentication",
35
+ "artatol"
44
36
  ],
45
37
  "author": "Artatol",
46
38
  "license": "MIT",
47
- "dependencies": {
48
- "@artatol-acp/auth-js": "workspace:*",
49
- "jose": "^6.1.3"
50
- },
51
39
  "peerDependencies": {
52
- "next": ">=15.0.0",
53
- "react": ">=18.0.0"
40
+ "next": "^14.0.0 || ^15.0.0",
41
+ "react": "^18.0.0 || ^19.0.0"
42
+ },
43
+ "dependencies": {
44
+ "@artatol-acp/auth-js": "^0.3.1",
45
+ "jose": "^5.9.6"
54
46
  },
55
47
  "devDependencies": {
56
- "@types/node": "^24.10.1",
57
- "@types/react": "^18.3.18",
58
- "next": "^15.1.6",
59
- "react": "^18.3.1",
60
- "typescript": "^5.7.2"
48
+ "@types/react": "^18.3.0",
49
+ "typescript": "^5.6.3"
61
50
  },
62
51
  "publishConfig": {
63
52
  "access": "public"
53
+ },
54
+ "scripts": {
55
+ "build": "tsc",
56
+ "dev": "tsc --watch",
57
+ "typecheck": "tsc --noEmit"
64
58
  }
65
59
  }