@meistrari/auth-core 1.14.0 → 1.15.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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +25 -10
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4533,7 +4533,7 @@ declare class ApplicationService {
|
|
|
4533
4533
|
* @throws {RefreshTokenExpiredError} When the refresh token has expired or is invalid
|
|
4534
4534
|
* @throws {ApplicationError} For other API errors
|
|
4535
4535
|
*/
|
|
4536
|
-
refreshAccessToken(refreshToken: string): Promise<CompleteAuthorizationFlowResponse>;
|
|
4536
|
+
refreshAccessToken(refreshToken: string): Promise<CompleteAuthorizationFlowResponse | null | undefined>;
|
|
4537
4537
|
/**
|
|
4538
4538
|
* Gets the current user and organization for a specific application.
|
|
4539
4539
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -4533,7 +4533,7 @@ declare class ApplicationService {
|
|
|
4533
4533
|
* @throws {RefreshTokenExpiredError} When the refresh token has expired or is invalid
|
|
4534
4534
|
* @throws {ApplicationError} For other API errors
|
|
4535
4535
|
*/
|
|
4536
|
-
refreshAccessToken(refreshToken: string): Promise<CompleteAuthorizationFlowResponse>;
|
|
4536
|
+
refreshAccessToken(refreshToken: string): Promise<CompleteAuthorizationFlowResponse | null | undefined>;
|
|
4537
4537
|
/**
|
|
4538
4538
|
* Gets the current user and organization for a specific application.
|
|
4539
4539
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { defaultStatements } from 'better-auth/plugins/organization/access';
|
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
export { APIError } from 'better-auth';
|
|
10
10
|
|
|
11
|
-
const version = "1.
|
|
11
|
+
const version = "1.15.0";
|
|
12
12
|
|
|
13
13
|
const statements = {
|
|
14
14
|
...defaultStatements,
|
|
@@ -418,11 +418,17 @@ class ApplicationService {
|
|
|
418
418
|
return response.data;
|
|
419
419
|
}
|
|
420
420
|
async exchangeDeviceCodeForTokens(deviceCode) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
421
|
+
try {
|
|
422
|
+
const response = await this.client.applications.exchangeDeviceCodeForTokens(deviceCode);
|
|
423
|
+
if (!response.data) {
|
|
424
|
+
throwDeviceGrantError(response.error);
|
|
425
|
+
}
|
|
426
|
+
return response.data;
|
|
427
|
+
} catch (error) {
|
|
428
|
+
if (error instanceof ApplicationError)
|
|
429
|
+
throw error;
|
|
430
|
+
throwDeviceGrantError(error);
|
|
424
431
|
}
|
|
425
|
-
return response.data;
|
|
426
432
|
}
|
|
427
433
|
/**
|
|
428
434
|
* Completes an authorization flow for a specific application.
|
|
@@ -445,16 +451,25 @@ class ApplicationService {
|
|
|
445
451
|
* @throws {ApplicationError} For other API errors
|
|
446
452
|
*/
|
|
447
453
|
async refreshAccessToken(refreshToken) {
|
|
448
|
-
const
|
|
449
|
-
if (!response.data) {
|
|
450
|
-
const error = response.error;
|
|
454
|
+
const handleRefreshError = (error) => {
|
|
451
455
|
const status = error?.status;
|
|
452
456
|
if (status === 404) {
|
|
453
457
|
throw new RefreshTokenExpiredError({ cause: error });
|
|
454
458
|
}
|
|
455
|
-
|
|
459
|
+
const message = error?.message;
|
|
460
|
+
throw new ApplicationError(message || "Failed to refresh access token", { cause: error });
|
|
461
|
+
};
|
|
462
|
+
try {
|
|
463
|
+
const response = await this.client.applications.refreshAccessToken(refreshToken);
|
|
464
|
+
if (!response.data) {
|
|
465
|
+
handleRefreshError(response.error);
|
|
466
|
+
}
|
|
467
|
+
return response.data;
|
|
468
|
+
} catch (error) {
|
|
469
|
+
if (error instanceof ApplicationError)
|
|
470
|
+
throw error;
|
|
471
|
+
handleRefreshError(error);
|
|
456
472
|
}
|
|
457
|
-
return response.data;
|
|
458
473
|
}
|
|
459
474
|
/**
|
|
460
475
|
* Gets the current user and organization for a specific application.
|