Skip to content

Commit e725f63

Browse files
feat(auth-next): add default auth without examples changes (#2795)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4ab37ef commit e725f63

File tree

26 files changed

+1238
-263
lines changed

26 files changed

+1238
-263
lines changed

.syncpackrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
"dependencyTypes": ["peer"],
1414
"packages": ["@imtbl/auth-next-server", "@imtbl/auth-next-client", "@imtbl/sdk"],
1515
"isIgnored": true
16+
},
17+
{
18+
"label": "Allow Next.js version flexibility in auth-next devDependencies",
19+
"dependencies": ["next"],
20+
"dependencyTypes": ["dev"],
21+
"packages": ["@imtbl/auth-next-server", "@imtbl/auth-next-client"],
22+
"isIgnored": true
1623
}
1724
]
1825
}

packages/auth-next-client/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ npm install @imtbl/auth-next-client @imtbl/auth-next-server next-auth@5
2727
- `next` >= 14.0.0
2828
- `next-auth` >= 5.0.0-beta.25
2929

30+
### Next.js 14 Compatibility
31+
32+
This package is compatible with both Next.js 14 and 15. It uses only standard APIs available in both versions (`next/navigation` for `useRouter`, `next-auth/react`). No Next.js 15-only APIs are used.
33+
3034
## Quick Start
3135

3236
### 1. Set Up Server-Side Auth
@@ -100,6 +104,42 @@ export default function Callback() {
100104
}
101105
```
102106

107+
### Default Auth (Zero Config)
108+
109+
When using `createAuthConfig()` with no args on the server, you can call login/logout with no config—sandbox clientId and redirectUri are used:
110+
111+
```tsx
112+
// With default auth - no config needed
113+
function LoginButton() {
114+
const { isAuthenticated } = useImmutableSession();
115+
const { loginWithPopup, isLoggingIn, error } = useLogin();
116+
117+
if (isAuthenticated) return <p>You are logged in!</p>;
118+
119+
return (
120+
<button onClick={() => loginWithPopup()} disabled={isLoggingIn}>
121+
{isLoggingIn ? "Signing in..." : "Sign In"}
122+
</button>
123+
);
124+
}
125+
```
126+
127+
Or with custom config (pass full LoginConfig/LogoutConfig when overriding):
128+
129+
```tsx
130+
// With custom config - pass complete config
131+
loginWithPopup({
132+
clientId: process.env.NEXT_PUBLIC_IMMUTABLE_CLIENT_ID!,
133+
redirectUri: `${window.location.origin}/callback`,
134+
});
135+
logout({
136+
clientId: process.env.NEXT_PUBLIC_IMMUTABLE_CLIENT_ID!,
137+
logoutRedirectUri: process.env.NEXT_PUBLIC_BASE_URL!,
138+
});
139+
```
140+
141+
See the [wallets-connect-with-nextjs](../../examples/passport/wallets-connect-with-nextjs) example for a full integration with `@imtbl/wallet`.
142+
103143
### 5. Add Login Button
104144

105145
Use the `useLogin` hook for login flows with built-in state management:

packages/auth-next-client/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@imtbl/auth-next-server": "workspace:*"
4141
},
4242
"peerDependencies": {
43-
"next": "^15.0.0",
43+
"next": "^14.0.0 || ^15.0.0",
4444
"next-auth": "^5.0.0-beta.25",
4545
"react": "^18.2.0 || ^19.0.0"
4646
},
@@ -65,7 +65,7 @@
6565
"@types/react": "^18.3.5",
6666
"eslint": "^8.56.0",
6767
"jest": "^29.7.0",
68-
"next": "^15.1.6",
68+
"next": "^15.2.6",
6969
"next-auth": "^5.0.0-beta.30",
7070
"react": "^18.2.0",
7171
"tsup": "^8.3.0",
Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,16 @@
11
/**
2-
* Shared constants for @imtbl/auth-next-client
2+
* Client-side constants for @imtbl/auth-next-client.
3+
* Defined locally to avoid importing from auth-next-server (which uses next/server).
4+
* Values must stay in sync with auth-next-server constants.
35
*/
46

5-
/**
6-
* Default Immutable authentication domain
7-
*/
87
export const DEFAULT_AUTH_DOMAIN = 'https://auth.immutable.com';
9-
10-
/**
11-
* Default OAuth audience
12-
*/
138
export const DEFAULT_AUDIENCE = 'platform_api';
14-
15-
/**
16-
* Default OAuth scopes
17-
*/
189
export const DEFAULT_SCOPE = 'openid profile email offline_access transact';
19-
20-
/**
21-
* NextAuth credentials provider ID for Immutable
22-
*/
2310
export const IMMUTABLE_PROVIDER_ID = 'immutable';
24-
25-
/**
26-
* Default NextAuth API base path
27-
*/
2811
export const DEFAULT_NEXTAUTH_BASE_PATH = '/api/auth';
29-
30-
/**
31-
* Default token expiry in seconds (15 minutes)
32-
* Used as fallback when exp claim cannot be extracted from JWT
33-
*/
34-
export const DEFAULT_TOKEN_EXPIRY_SECONDS = 900;
35-
36-
/**
37-
* Default token expiry in milliseconds
38-
*/
39-
export const DEFAULT_TOKEN_EXPIRY_MS = DEFAULT_TOKEN_EXPIRY_SECONDS * 1000;
40-
41-
/**
42-
* Buffer time in milliseconds before token expiry to trigger refresh.
43-
* Matches TOKEN_EXPIRY_BUFFER_SECONDS (60s) in @imtbl/auth-next-server.
44-
*/
45-
export const TOKEN_EXPIRY_BUFFER_MS = 60 * 1000;
12+
export const DEFAULT_SANDBOX_CLIENT_ID = 'mjtCL8mt06BtbxSkp2vbrYStKWnXVZfo';
13+
export const DEFAULT_REDIRECT_URI_PATH = '/callback';
14+
export const DEFAULT_LOGOUT_REDIRECT_URI_PATH = '/';
15+
export const DEFAULT_TOKEN_EXPIRY_MS = 900_000;
16+
export const TOKEN_EXPIRY_BUFFER_MS = 60_000;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Sandbox default redirect URI for zero-config mode.
3+
* Defined locally to avoid importing from auth-next-server (which uses next/server).
4+
* OAuth requires an absolute URL; this runs in the browser when login is invoked.
5+
*
6+
* @internal
7+
*/
8+
9+
import { DEFAULT_REDIRECT_URI_PATH } from './constants';
10+
11+
export function deriveDefaultRedirectUri(): string {
12+
if (typeof window === 'undefined') {
13+
throw new Error(
14+
'[auth-next-client] deriveDefaultRedirectUri requires window. '
15+
+ 'Login hooks run in the browser when the user triggers login.',
16+
);
17+
}
18+
return `${window.location.origin}${DEFAULT_REDIRECT_URI_PATH}`;
19+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ jest.mock('@imtbl/auth', () => ({
2323
logoutWithRedirect: jest.fn(),
2424
}));
2525

26+
jest.mock('./defaultConfig', () => ({
27+
deriveDefaultRedirectUri: jest.fn(() => 'http://localhost:3000/callback'),
28+
}));
29+
2630
import { useImmutableSession } from './hooks';
2731

2832
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)