Skip to content

Commit bd1f8b3

Browse files
committed
Rename MayRLabsAuthError to AuthError
Rename the legacy MayRLabsAuthError class to AuthError and update all usages across the repo. Propagated changes to errors, core/base, core/client, and tests to throw/check AuthError instead of the old name. Updated @mayrlabs/auth and @mayrlabs/auth-nextjs package versions to 0.5.1, adjusted auth-nextjs exports to re-export AuthError, related payload types, and utility functions (generateCodeChallenge, generateCodeVerifier, generateRandomString). Changelogs were updated to reflect the rename and the new patch release.
1 parent 386e1aa commit bd1f8b3

9 files changed

Lines changed: 51 additions & 27 deletions

File tree

packages/auth-nextjs/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
# Changelog
22

3+
## [0.5.1] - 2026-04-10
4+
5+
### Breaking Changes
6+
7+
- Exported `AuthError` from `@mayrlabs/auth`
8+
- Exported `generateCodeChallenge`, `generateCodeVerifier` and `generateRandomString` util functions from `@mayrlabs/auth`
9+
10+
### Fixes
11+
12+
Fixed exports of `AuthErrorPayload`, `AuthMachinePayload`, `AuthUserPayload` from `@mayrlabs/auth`
13+
314
## [0.5.0] - 2026-04-10
415

516
### ⚠️ Breaking Changes
17+
618
- `redirectToLogin()` no longer requires the `NextRequest` parameter as it uses absolute URL redirection.
719
- `getUserOrRedirect` and `AuthProvider` now redirect to the local `redirects.error` path (default `/login`) instead of absolute SSO URLs in server context.
820

921
### Features
22+
1023
- **CSRF Protection**: Added robust state-parameter verification for all SSO flows using `httpOnly` cookies (5-minute expiry).
1124
- **Security Hardening**: The state cookie is now immediately deleted after consumption in `handleCallback` to maximize security.
1225
- **Configurable State Key**: Added `MAYRLABS_AUTH_STATE_KEY` env variable and `cookie.stateKey` option to customize the CSRF state cookie name.
@@ -19,6 +32,7 @@
1932
## [0.4.2] - 2026-04-08
2033

2134
### Breaking Changes
35+
2236
- Updated session key defaults to prevent collision between Client and Issuer sessions.
2337
- Default Client key: `mayrlabs-client-session`
2438
- Default Issuer key: `mayrlabs-issuer-session`

packages/auth-nextjs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mayrlabs/auth-nextjs",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "The official Next.js App Router integration for @mayrlabs/auth featuring Middleware guards, Server Actions utilities, and React Context bindings.",
55
"keywords": [
66
"nextjs",
@@ -116,7 +116,7 @@
116116
"react-dom": "^18.0.0 || ^19.0.0 || ^20.0.0"
117117
},
118118
"dependencies": {
119-
"@mayrlabs/auth": "^0.5.0",
119+
"@mayrlabs/auth": "^0.5.1",
120120
"@t3-oss/env-nextjs": "^0.12.0",
121121
"zod": "^3.24.2"
122122
},

packages/auth-nextjs/src/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
export {
2+
AuthError,
3+
type AuthErrorPayload,
4+
type AuthMachinePayload,
5+
type AuthUserPayload,
26
BaseAuthSetup,
37
ClientAuthSetup,
48
type ClientConfig,
59
type ClientConfigInput,
10+
generateCodeChallenge,
11+
generateCodeVerifier,
12+
generateRandomString,
613
IssuerAuthSetup,
714
type IssuerConfig,
815
type IssuerConfigInput,
9-
MayRLabsAuthError,
10-
type MayRLabsAuthErrorPayload,
11-
type MayRLabsAuthMachinePayload,
12-
type MayRLabsAuthUserPayload,
1316
UnauthenticatedError,
1417
} from "@mayrlabs/auth";
1518
export * from "./client";

packages/auth/CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# Changelog
22

3+
## [0.5.1] - 2026-04-10
4+
5+
### Breaking Changes
6+
7+
- Renamed `MayRLabsAuthError` -> `AuthError`
8+
39
## [0.5.0] - 2026-04-10
410

511
### Features
12+
613
- **CSRF Protection**: Implemented state-parameter verification for SSO flows to prevent forgery.
714
- **Node.js Compatibility**: Improved `b64url` encoding to utilize `Buffer` when available, ensuring compatibility with Next.js Server Actions and Middleware.
815
- **User Model**: Renamed `MayRLabsUser` to `AuthUser` and aligned interface with the Account Center (`id`, `username`, nullable name fields).
@@ -14,6 +21,7 @@
1421
## [0.4.2] - 2026-04-08
1522

1623
### Breaking Changes
24+
1725
- Separated session cookie keys for client and issuer applications.
1826
- Updated default session key to `mayrlabs-client-session` (Client) and `mayrlabs-issuer-session` (Issuer).
1927

@@ -63,7 +71,7 @@ Minor bump to ensure version sync
6371
- `IssuerAuthSetup`: For identity providers (signing tokens with Private JWK).
6472
- `ClientAuthSetup`: For consumer applications (verifying tokens with Public JWK and machine authentication).
6573
- **JWK Integration**: Switched to JSON Web Key (JWK) standard for key management with built-in caching for performance.
66-
- **Strict Typing**: Removed all `any` types and implemented exhaustive TypeScript interfaces for `MayRLabsAuthUserPayload`, `MayRLabsAuthMachinePayload`, and `MayRLabsAuthErrorPayload`.
74+
- **Strict Typing**: Removed all `any` types and implemented exhaustive TypeScript interfaces for `MayRLabsAuthUserPayload`, `MayRLabsAuthMachinePayload`, and `AuthErrorPayload`.
6775
- **Breaking Changes**: Fully removed legacy symmetric encryption utilities (`src/core/encryption.ts`).
6876

6977
## 0.1.2

packages/auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mayrlabs/auth",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "A strictly typed, universal JWT and M2M authentication core library powering the MayR Labs ecosystem.",
55
"keywords": [
66
"auth",

packages/auth/src/core/base.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Buffer } from "node:buffer";
22
import { exportJWK, generateKeyPair, importJWK, SignJWT } from "jose";
33
import { beforeEach, describe, expect, it, vi } from "vitest";
4+
import { AuthError } from "../errors";
5+
import { BaseAuthSetup } from "./base";
46

57
vi.mock("jose", async (importOriginal) => {
68
// biome-ignore lint/suspicious/noExplicitAny: Test
@@ -13,9 +15,6 @@ vi.mock("jose", async (importOriginal) => {
1315
};
1416
});
1517

16-
import { MayRLabsAuthError } from "../errors";
17-
import { BaseAuthSetup } from "./base";
18-
1918
class MockAuthSetup extends BaseAuthSetup<{
2019
publicKey?: string;
2120
issuer: string;
@@ -52,9 +51,9 @@ describe("BaseAuthSetup", () => {
5251
await setup.testGetKey("invalid-json", "Public");
5352
expect.fail("Should have thrown");
5453
} catch (error) {
55-
expect(error).toBeInstanceOf(MayRLabsAuthError);
56-
expect((error as MayRLabsAuthError).code).toBe("INVALID_PUBLIC_KEY");
57-
expect((error as MayRLabsAuthError).message).toContain(
54+
expect(error).toBeInstanceOf(AuthError);
55+
expect((error as AuthError).code).toBe("INVALID_PUBLIC_KEY");
56+
expect((error as AuthError).message).toContain(
5857
"Failed to import Public JWK",
5958
);
6059
}
@@ -64,7 +63,7 @@ describe("BaseAuthSetup", () => {
6463
const setup = new MockAuthSetup({ publicKey: publicJWK, issuer: ISSUER });
6564
await expect(
6665
setup.testGetKey(JSON.stringify({ kty: "oct", k: "..." }), "Public"),
67-
).rejects.toThrow(MayRLabsAuthError);
66+
).rejects.toThrow(AuthError);
6867
});
6968
});
7069

packages/auth/src/core/base.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type JWTVerifyGetKey,
66
jwtVerify,
77
} from "jose";
8-
import { MayRLabsAuthError } from "../errors";
8+
import { AuthError } from "../errors";
99
import type {
1010
AuthErrorPayload,
1111
AuthMachinePayload,
@@ -37,7 +37,7 @@ export abstract class BaseAuthSetup<
3737
try {
3838
return (await importJWK(JSON.parse(keyString), "PS256")) as CryptoKey;
3939
} catch (error) {
40-
throw new MayRLabsAuthError(
40+
throw new AuthError(
4141
`Failed to import ${keyType} JWK: ${error instanceof Error ? error.message : "Unknown error"}`,
4242
`INVALID_${keyType.toUpperCase()}_KEY`,
4343
);
@@ -54,7 +54,7 @@ export abstract class BaseAuthSetup<
5454
}
5555

5656
if (!this.config.publicKey) {
57-
throw new MayRLabsAuthError(
57+
throw new AuthError(
5858
"Local public key missing and remotePublicKey not enabled.",
5959
"MISSING_PUBLIC_KEY",
6060
);
@@ -84,7 +84,7 @@ export abstract class BaseAuthSetup<
8484

8585
return payload as ResponseT;
8686
} catch (error) {
87-
if (error instanceof MayRLabsAuthError) throw error;
87+
if (error instanceof AuthError) throw error;
8888

8989
return null;
9090
}

packages/auth/src/core/client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MayRLabsAuthError } from "../errors";
1+
import { AuthError } from "../errors";
22
import type {
33
AuthErrorPayload,
44
AuthUserPayload,
@@ -48,7 +48,7 @@ export class ClientAuthSetup extends BaseAuthSetup<ClientConfig> {
4848
*
4949
* @returns A promise that resolves to the machine authentication token.
5050
*
51-
* @throws {MayRLabsAuthError} If authentication fails or network error occurs.
51+
* @throws {AuthError} If authentication fails or network error occurs.
5252
*/
5353
async authenticateMachine(): Promise<string> {
5454
try {
@@ -70,7 +70,7 @@ export class ClientAuthSetup extends BaseAuthSetup<ClientConfig> {
7070
code?: string;
7171
};
7272

73-
throw new MayRLabsAuthError(
73+
throw new AuthError(
7474
errorData.message || "Failed to authenticate machine",
7575
errorData.code || "MACHINE_AUTH_FAILED",
7676
);
@@ -80,9 +80,9 @@ export class ClientAuthSetup extends BaseAuthSetup<ClientConfig> {
8080

8181
return data.token;
8282
} catch (error) {
83-
if (error instanceof MayRLabsAuthError) throw error;
83+
if (error instanceof AuthError) throw error;
8484

85-
throw new MayRLabsAuthError(
85+
throw new AuthError(
8686
`Machine authentication network error: ${error instanceof Error ? error.message : "Unknown error"}`,
8787
"MACHINE_AUTH_NETWORK_ERROR",
8888
);

packages/auth/src/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
export class MayRLabsAuthError extends Error {
1+
export class AuthError extends Error {
22
constructor(
33
message: string,
44
public readonly code: string = "AUTH_ERROR",
55
) {
66
super(message);
7-
this.name = "MayRLabsAuthError";
7+
this.name = "AuthError";
88
}
99
}
1010

11-
export class UnauthenticatedError extends MayRLabsAuthError {
11+
export class UnauthenticatedError extends AuthError {
1212
constructor(message: string = "User is not authenticated.") {
1313
super(message, "UNAUTHENTICATED");
1414
this.name = "UnauthenticatedError";

0 commit comments

Comments
 (0)