Skip to content

Commit 3b92d82

Browse files
refactor(auth-next): remove unused code and enforce valid redirect URIs
- Remove DEFAULT_PRODUCTION_CLIENT_ID (unused in auth-next) - Throw when window undefined in deriveDefaultRedirectUri and getSandboxLogoutConfig (OAuth requires absolute URLs; path-only is invalid) - Inline resolvedConfig in createAuthConfig: config ?? { ... }
1 parent 866ebd8 commit 3b92d82

7 files changed

Lines changed: 16 additions & 28 deletions

File tree

packages/auth-next-client/src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const DEFAULT_AUDIENCE = 'platform_api';
99
export const DEFAULT_SCOPE = 'openid profile email offline_access transact';
1010
export const IMMUTABLE_PROVIDER_ID = 'immutable';
1111
export const DEFAULT_NEXTAUTH_BASE_PATH = '/api/auth';
12-
export const DEFAULT_PRODUCTION_CLIENT_ID = 'PtQRK4iRJ8GkXjiz6xfImMAYhPhW0cYk';
1312
export const DEFAULT_SANDBOX_CLIENT_ID = 'mjtCL8mt06BtbxSkp2vbrYStKWnXVZfo';
1413
export const DEFAULT_REDIRECT_URI_PATH = '/callback';
1514
export const DEFAULT_POPUP_REDIRECT_URI_PATH = '/callback';
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Sandbox default redirect URI for zero-config mode.
33
* Defined locally to avoid importing from auth-next-server (which uses next/server).
4-
* Server: path only. Client: full URL (origin + path).
4+
* OAuth requires an absolute URL; this runs in the browser when login is invoked.
55
*
66
* @internal
77
*/
@@ -10,7 +10,10 @@ import { DEFAULT_REDIRECT_URI_PATH } from './constants';
1010

1111
export function deriveDefaultRedirectUri(): string {
1212
if (typeof window === 'undefined') {
13-
return DEFAULT_REDIRECT_URI_PATH;
13+
throw new Error(
14+
'[auth-next-client] deriveDefaultRedirectUri requires window. '
15+
+ 'Login hooks run in the browser when the user triggers login.',
16+
);
1417
}
1518
return `${window.location.origin}${DEFAULT_REDIRECT_URI_PATH}`;
1619
}

packages/auth-next-client/src/hooks.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,13 @@ function getSandboxLoginConfig(): LoginConfig {
6868
}
6969

7070
function getSandboxLogoutConfig(): LogoutConfig {
71-
const logoutRedirectUri = typeof window === 'undefined'
72-
? DEFAULT_LOGOUT_REDIRECT_URI_PATH
73-
: window.location.origin + DEFAULT_LOGOUT_REDIRECT_URI_PATH;
71+
if (typeof window === 'undefined') {
72+
throw new Error(
73+
'[auth-next-client] getSandboxLogoutConfig requires window. '
74+
+ 'Logout runs in the browser when the user triggers it.',
75+
);
76+
}
77+
const logoutRedirectUri = window.location.origin + DEFAULT_LOGOUT_REDIRECT_URI_PATH;
7478
return {
7579
clientId: DEFAULT_SANDBOX_CLIENT_ID,
7680
logoutRedirectUri,

packages/auth-next-client/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export {
6666
DEFAULT_AUDIENCE,
6767
DEFAULT_SCOPE,
6868
IMMUTABLE_PROVIDER_ID,
69-
DEFAULT_PRODUCTION_CLIENT_ID,
7069
DEFAULT_SANDBOX_CLIENT_ID,
7170
DEFAULT_REDIRECT_URI_PATH,
7271
DEFAULT_POPUP_REDIRECT_URI_PATH,

packages/auth-next-server/src/config.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,9 @@ async function validateTokens(
8787
* ```
8888
*/
8989
export function createAuthConfig(config?: ImmutableAuthConfig): NextAuthConfig {
90-
let clientId: string;
91-
let redirectUri: string;
92-
93-
if (config) {
94-
clientId = config.clientId;
95-
redirectUri = config.redirectUri;
96-
} else {
97-
clientId = DEFAULT_SANDBOX_CLIENT_ID;
98-
redirectUri = deriveDefaultRedirectUri();
99-
}
100-
101-
const resolvedConfig: ImmutableAuthConfig = {
102-
clientId,
103-
redirectUri,
104-
audience: config?.audience,
105-
scope: config?.scope,
106-
authenticationDomain: config?.authenticationDomain,
90+
const resolvedConfig: ImmutableAuthConfig = config ?? {
91+
clientId: DEFAULT_SANDBOX_CLIENT_ID,
92+
redirectUri: deriveDefaultRedirectUri(),
10793
};
10894
const authDomain = resolvedConfig.authenticationDomain || DEFAULT_AUTH_DOMAIN;
10995

packages/auth-next-server/src/constants.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ export const TOKEN_EXPIRY_BUFFER_MS = TOKEN_EXPIRY_BUFFER_SECONDS * 1000;
5757
export const DEFAULT_SESSION_MAX_AGE_SECONDS = 365 * 24 * 60 * 60;
5858

5959
/**
60-
* Public client IDs for Immutable's default applications.
61-
* auth-next zero-config uses DEFAULT_SANDBOX_CLIENT_ID only.
60+
* Sandbox client ID for auth-next zero-config.
6261
*/
63-
export const DEFAULT_PRODUCTION_CLIENT_ID = 'PtQRK4iRJ8GkXjiz6xfImMAYhPhW0cYk';
6462
export const DEFAULT_SANDBOX_CLIENT_ID = 'mjtCL8mt06BtbxSkp2vbrYStKWnXVZfo';
6563

6664
/**

packages/auth-next-server/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export {
5151
DEFAULT_SCOPE,
5252
IMMUTABLE_PROVIDER_ID,
5353
DEFAULT_NEXTAUTH_BASE_PATH,
54-
DEFAULT_PRODUCTION_CLIENT_ID,
5554
DEFAULT_SANDBOX_CLIENT_ID,
5655
DEFAULT_REDIRECT_URI_PATH,
5756
DEFAULT_POPUP_REDIRECT_URI_PATH,

0 commit comments

Comments
 (0)