Skip to content

Commit c1e61bb

Browse files
fix(sample-app): align default auth flow, callback path, and login visibility
- Move example callback from /callback-auth-next to /callback for zero-config - Handle DEFAULT enum in NFT/ERC20 switch statements (use sandbox values) - Add mutual exclusivity: Auth NextJS vs Passport Methods by login type - Defer conditional rendering until mount to fix hydration mismatch Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 051f252 commit c1e61bb

8 files changed

Lines changed: 58 additions & 26 deletions

File tree

examples/passport/wallets-connect-with-nextjs/app/callback-auth-next/page.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use client";
2+
3+
import { CallbackPage, DEFAULT_SANDBOX_CLIENT_ID, deriveDefaultRedirectUri } from "@imtbl/auth-next-client";
4+
5+
export default function AuthCallback() {
6+
// Use default sandbox config to match zero-config login flow (getSandboxLoginConfig)
7+
const config = {
8+
clientId: DEFAULT_SANDBOX_CLIENT_ID,
9+
redirectUri: deriveDefaultRedirectUri(),
10+
};
11+
12+
return (
13+
<div style={{ padding: '2rem', textAlign: 'center' }}>
14+
<h1>Processing authentication...</h1>
15+
<CallbackPage config={config} redirectTo="/connect-with-auth-next" />
16+
</div>
17+
);
18+
}

packages/passport/sdk-sample-app/src/components/zkevm/EthSendTransactionExamples/NFTApproval.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ enum ApproveType {
1616
const getErc721DefaultContractAddress = (environment: EnvironmentNames) => {
1717
switch (environment) {
1818
case EnvironmentNames.SANDBOX:
19+
case EnvironmentNames.DEFAULT:
1920
return '0xbe499b1eaa5c9992486be90ad3a3a4c15dcdfcda';
2021
case EnvironmentNames.PRODUCTION:
2122
return '0xb7d76448b0e887ce731e8d17c97ad605df412fb0';

packages/passport/sdk-sample-app/src/components/zkevm/EthSendTransactionExamples/NFTTransfer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type NFTCandidate = BlockchainData.NFTWithBalance & {
2929
const chainNameMapping = (environment: EnvironmentNames) => {
3030
switch (environment) {
3131
case EnvironmentNames.SANDBOX:
32+
case EnvironmentNames.DEFAULT:
3233
return 'imtbl-zkevm-testnet';
3334
case EnvironmentNames.PRODUCTION:
3435
return 'imtbl-zkevm-mainnet';

packages/passport/sdk-sample-app/src/components/zkevm/EthSendTransactionExamples/SpendingCapApproval.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Interface } from 'ethers';
1111
const getErc20DefaultContractAddress = (environment: EnvironmentNames) => {
1212
switch (environment) {
1313
case EnvironmentNames.SANDBOX:
14+
case EnvironmentNames.DEFAULT:
1415
return '0x7bbe61ba86dc1b128b7c6228a4834bf2c1394240';
1516
case EnvironmentNames.PRODUCTION:
1617
return '0x52a6c53869ce09a731cd772f245b97a4401d3348';

packages/passport/sdk-sample-app/src/components/zkevm/EthSendTransactionExamples/TransferERC20.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Interface } from 'ethers';
1515
const getErc20DefaultContractAddress = (environment: EnvironmentNames) => {
1616
switch (environment) {
1717
case EnvironmentNames.SANDBOX:
18+
case EnvironmentNames.DEFAULT:
1819
return '0x7bbe61ba86dc1b128b7c6228a4834bf2c1394240';
1920
case EnvironmentNames.PRODUCTION:
2021
return '0x52a6c53869ce09a731cd772f245b97a4401d3348';

packages/passport/sdk-sample-app/src/components/zkevm/ZkEvmWorkflow.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const getChainConfig = (environment: EnvironmentNames): ChainConfig[] | undefine
3333
magicProviderId: 'd196052b-8175-4a45-ba13-838a715d370f',
3434
}];
3535
case EnvironmentNames.SANDBOX:
36+
case EnvironmentNames.DEFAULT:
3637
// Use testnet (default chain in wallet package)
3738
return undefined;
3839
case EnvironmentNames.PRODUCTION:

packages/passport/sdk-sample-app/src/pages/index.page.tsx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import Head from 'next/head';
33
import { Container, Row } from 'react-bootstrap';
44
import { useImmutableSession } from '@imtbl/auth-next-client';
@@ -8,18 +8,42 @@ import Message from '@/components/Message';
88
import Environment from '@/components/Environment';
99
import { usePassportProvider } from '@/context/PassportProvider';
1010
import { useStatusProvider } from '@/context/StatusProvider';
11+
import { useImmutableProvider } from '@/context/ImmutableProvider';
1112
import { BASE_PATH } from '@/config';
1213
import PassportMethods from '@/components/PassportMethods';
1314
import ZkEvmWorkflow from '@/components/zkevm/ZkEvmWorkflow';
1415
import AuthNextJS from '@/components/AuthNextJS';
16+
import { EnvironmentNames } from '@/types';
1517

18+
/**
19+
* Login flow visibility rules:
20+
* - DEFAULT env: only Auth NextJS (SSR) makes sense; Passport Methods hidden
21+
* - Logged in via SSR: Passport Methods hidden (mutually exclusive)
22+
* - Logged in via Passport (imx/zkEvm): Auth NextJS hidden (mutually exclusive)
23+
*
24+
* Conditional rendering is deferred until after mount to avoid hydration mismatch:
25+
* environment (localStorage), session, and providers differ between server and client.
26+
*/
1627
export default function Home() {
28+
const [hasMounted, setHasMounted] = useState(false);
1729
const { isLoading } = useStatusProvider();
30+
const { environment } = useImmutableProvider();
1831
const {
1932
imxProvider, zkEvmProvider, defaultWalletProvider,
2033
} = usePassportProvider();
2134
const { isAuthenticated: isAuthNextJSAuthenticated } = useImmutableSession();
2235

36+
useEffect(() => {
37+
setHasMounted(true);
38+
}, []);
39+
40+
const isDefaultEnv = environment === EnvironmentNames.DEFAULT;
41+
const isPassportConnected = !!imxProvider || !!zkEvmProvider;
42+
43+
// Before mount: show both for consistent server/client HTML (avoids hydration mismatch)
44+
const showAuthNextJS = !hasMounted || isDefaultEnv || !isPassportConnected;
45+
const showPassportMethods = !hasMounted || (!isDefaultEnv && !isAuthNextJSAuthenticated);
46+
2347
return (
2448
<>
2549
<Head>
@@ -36,12 +60,16 @@ export default function Home() {
3660
|| !!defaultWalletProvider || isAuthNextJSAuthenticated}
3761
/>
3862
</Row>
39-
<Row className="my-3">
40-
<AuthNextJS />
41-
</Row>
42-
<Row className="my-3">
43-
<PassportMethods />
44-
</Row>
63+
{showAuthNextJS && (
64+
<Row className="my-3">
65+
<AuthNextJS />
66+
</Row>
67+
)}
68+
{showPassportMethods && (
69+
<Row className="my-3">
70+
<PassportMethods />
71+
</Row>
72+
)}
4573
<Row className="my-3">
4674
<ImxWorkflow />
4775
</Row>

0 commit comments

Comments
 (0)