lens-convex-auth 0.1.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/LICENSE +21 -0
- package/README.md +357 -0
- package/dist/auth-Baitf7Ze.d.ts +102 -0
- package/dist/chunk-2UCSL2CL.js +526 -0
- package/dist/chunk-2UCSL2CL.js.map +1 -0
- package/dist/chunk-CDAKZCYM.js +22 -0
- package/dist/chunk-CDAKZCYM.js.map +1 -0
- package/dist/cli/index.js +36 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/convex/index.d.ts +25 -0
- package/dist/convex/index.js +35 -0
- package/dist/convex/index.js.map +1 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +83 -0
- package/dist/react/index.js +1271 -0
- package/dist/react/index.js.map +1 -0
- package/dist/server/index.d.ts +33 -0
- package/dist/server/index.js +78 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +105 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli/index.ts
|
|
4
|
+
import { exportJWK, exportPKCS8, generateKeyPair } from "jose";
|
|
5
|
+
|
|
6
|
+
// src/core/constants.ts
|
|
7
|
+
var LENS_TOKEN_LIFETIME_MS = 10 * 60 * 1e3;
|
|
8
|
+
var DEFAULT_CONVEX_TOKEN_KEY_ID = "convex-auth-1";
|
|
9
|
+
|
|
10
|
+
// src/cli/index.ts
|
|
11
|
+
var USAGE = `Usage: npx lens-convex-auth keys [--kid <key id>]
|
|
12
|
+
|
|
13
|
+
Generates the key pair Convex auth tokens are signed with, and prints:
|
|
14
|
+
CONVEX_AUTH_PRIVATE_KEY set on your server (.env.local, Vercel). Keep it secret.
|
|
15
|
+
CONVEX_AUTH_JWKS set on your Convex deployment:
|
|
16
|
+
npx convex env set CONVEX_AUTH_JWKS '<value>'
|
|
17
|
+
|
|
18
|
+
Generate one pair per environment (dev, prod) and set both halves of a pair together.
|
|
19
|
+
Pass --kid only if you also pass the same keyId to createConvexTokenHandler.`;
|
|
20
|
+
async function keys(kid) {
|
|
21
|
+
const { publicKey, privateKey } = await generateKeyPair("RS256", { extractable: true });
|
|
22
|
+
const pem = await exportPKCS8(privateKey);
|
|
23
|
+
const jwk = { ...await exportJWK(publicKey), kid, alg: "RS256", use: "sig" };
|
|
24
|
+
const jwks = JSON.stringify({ keys: [jwk] });
|
|
25
|
+
console.log(`CONVEX_AUTH_PRIVATE_KEY="${pem.trim().replace(/\n/g, "\\n")}"`);
|
|
26
|
+
console.log(`CONVEX_AUTH_JWKS=data:text/plain;charset=utf-8;base64,${Buffer.from(jwks).toString("base64")}`);
|
|
27
|
+
}
|
|
28
|
+
var [command, ...args] = process.argv.slice(2);
|
|
29
|
+
if (command === "keys") {
|
|
30
|
+
const kidIndex = args.indexOf("--kid");
|
|
31
|
+
await keys(kidIndex >= 0 && args[kidIndex + 1] ? args[kidIndex + 1] : DEFAULT_CONVEX_TOKEN_KEY_ID);
|
|
32
|
+
} else {
|
|
33
|
+
console.log(USAGE);
|
|
34
|
+
process.exit(command ? 1 : 0);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cli/index.ts","../../src/core/constants.ts"],"sourcesContent":["import { exportJWK, exportPKCS8, generateKeyPair } from \"jose\"\nimport { DEFAULT_CONVEX_TOKEN_KEY_ID } from \"../core/constants\"\n\nconst USAGE = `Usage: npx lens-convex-auth keys [--kid <key id>]\n\nGenerates the key pair Convex auth tokens are signed with, and prints:\n CONVEX_AUTH_PRIVATE_KEY set on your server (.env.local, Vercel). Keep it secret.\n CONVEX_AUTH_JWKS set on your Convex deployment:\n npx convex env set CONVEX_AUTH_JWKS '<value>'\n\nGenerate one pair per environment (dev, prod) and set both halves of a pair together.\nPass --kid only if you also pass the same keyId to createConvexTokenHandler.`\n\nasync function keys(kid: string) {\n const { publicKey, privateKey } = await generateKeyPair(\"RS256\", { extractable: true })\n const pem = await exportPKCS8(privateKey)\n const jwk = { ...(await exportJWK(publicKey)), kid, alg: \"RS256\", use: \"sig\" }\n const jwks = JSON.stringify({ keys: [jwk] })\n console.log(`CONVEX_AUTH_PRIVATE_KEY=\"${pem.trim().replace(/\\n/g, \"\\\\n\")}\"`)\n console.log(`CONVEX_AUTH_JWKS=data:text/plain;charset=utf-8;base64,${Buffer.from(jwks).toString(\"base64\")}`)\n}\n\nconst [command, ...args] = process.argv.slice(2)\nif (command === \"keys\") {\n const kidIndex = args.indexOf(\"--kid\")\n await keys(kidIndex >= 0 && args[kidIndex + 1] ? args[kidIndex + 1] : DEFAULT_CONVEX_TOKEN_KEY_ID)\n} else {\n console.log(USAGE)\n process.exit(command ? 1 : 0)\n}\n","// Dependency-free values shared by every entry point, including the server and Convex ones.\n\nexport type LensEnvironmentName = \"mainnet\" | \"testnet\"\n\nconst LENS_API_ORIGINS: Record<LensEnvironmentName, string> = {\n mainnet: \"https://api.lens.xyz\",\n testnet: \"https://api.testnet.lens.xyz\",\n}\n\n// Lens signs its tokens as the API origin, and publishes its keys under it.\nexport function lensApiOrigin(environment: LensEnvironmentName = \"mainnet\"): string {\n return LENS_API_ORIGINS[environment]\n}\n\nexport const LENS_CHAIN_IDS: Record<LensEnvironmentName, number> = {\n mainnet: 232,\n testnet: 37111,\n}\n\n// Lens access and ID tokens are valid for 10 minutes.\nexport const LENS_TOKEN_LIFETIME_MS = 10 * 60 * 1000\n\nexport const ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/\n\n// The token the server issues for Convex (server/, convex/, cli/). Both sides must agree on these.\nexport const DEFAULT_CONVEX_TOKEN_ISSUER = \"https://lens-convex-auth.local\"\nexport const DEFAULT_CONVEX_TOKEN_AUDIENCE = \"convex\"\nexport const DEFAULT_CONVEX_TOKEN_KEY_ID = \"convex-auth-1\"\nexport const DEFAULT_CONVEX_TOKEN_ENDPOINT = \"/api/convex-token\"\n"],"mappings":";;;AAAA,SAAS,WAAW,aAAa,uBAAuB;;;ACoBjD,IAAM,yBAAyB,KAAK,KAAK;AAOzC,IAAM,8BAA8B;;;ADxB3C,IAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUd,eAAe,KAAK,KAAa;AAC/B,QAAM,EAAE,WAAW,WAAW,IAAI,MAAM,gBAAgB,SAAS,EAAE,aAAa,KAAK,CAAC;AACtF,QAAM,MAAM,MAAM,YAAY,UAAU;AACxC,QAAM,MAAM,EAAE,GAAI,MAAM,UAAU,SAAS,GAAI,KAAK,KAAK,SAAS,KAAK,MAAM;AAC7E,QAAM,OAAO,KAAK,UAAU,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;AAC3C,UAAQ,IAAI,4BAA4B,IAAI,KAAK,EAAE,QAAQ,OAAO,KAAK,CAAC,GAAG;AAC3E,UAAQ,IAAI,yDAAyD,OAAO,KAAK,IAAI,EAAE,SAAS,QAAQ,CAAC,EAAE;AAC7G;AAEA,IAAM,CAAC,SAAS,GAAG,IAAI,IAAI,QAAQ,KAAK,MAAM,CAAC;AAC/C,IAAI,YAAY,QAAQ;AACtB,QAAM,WAAW,KAAK,QAAQ,OAAO;AACrC,QAAM,KAAK,YAAY,KAAK,KAAK,WAAW,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,2BAA2B;AACnG,OAAO;AACL,UAAQ,IAAI,KAAK;AACjB,UAAQ,KAAK,UAAU,IAAI,CAAC;AAC9B;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Auth } from 'convex/server';
|
|
2
|
+
|
|
3
|
+
type LensAuthProviderOptions = {
|
|
4
|
+
/** Public key from `npx lens-convex-auth keys`. Defaults to process.env.CONVEX_AUTH_JWKS */
|
|
5
|
+
jwks?: string;
|
|
6
|
+
/** Must match the server's `issuer` option */
|
|
7
|
+
issuer?: string;
|
|
8
|
+
/** Must match the server's `audience` option */
|
|
9
|
+
audience?: string;
|
|
10
|
+
};
|
|
11
|
+
declare function lensAuthProvider(options?: LensAuthProviderOptions): {
|
|
12
|
+
type: "customJwt";
|
|
13
|
+
applicationID: string;
|
|
14
|
+
issuer: string;
|
|
15
|
+
jwks: string;
|
|
16
|
+
algorithm: "RS256";
|
|
17
|
+
};
|
|
18
|
+
declare function getLensAccount(ctx: {
|
|
19
|
+
auth: Auth;
|
|
20
|
+
}): Promise<string | null>;
|
|
21
|
+
declare function requireLensAccount(ctx: {
|
|
22
|
+
auth: Auth;
|
|
23
|
+
}, message?: string): Promise<string>;
|
|
24
|
+
|
|
25
|
+
export { type LensAuthProviderOptions, getLensAccount, lensAuthProvider, requireLensAccount };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ADDRESS_RE,
|
|
3
|
+
DEFAULT_CONVEX_TOKEN_AUDIENCE,
|
|
4
|
+
DEFAULT_CONVEX_TOKEN_ISSUER
|
|
5
|
+
} from "../chunk-CDAKZCYM.js";
|
|
6
|
+
|
|
7
|
+
// src/convex/index.ts
|
|
8
|
+
import { ConvexError } from "convex/values";
|
|
9
|
+
function lensAuthProvider(options = {}) {
|
|
10
|
+
const jwks = options.jwks ?? process.env.CONVEX_AUTH_JWKS;
|
|
11
|
+
if (!jwks) throw new Error("lens-convex-auth: set CONVEX_AUTH_JWKS on your Convex deployment");
|
|
12
|
+
return {
|
|
13
|
+
type: "customJwt",
|
|
14
|
+
applicationID: options.audience ?? DEFAULT_CONVEX_TOKEN_AUDIENCE,
|
|
15
|
+
issuer: options.issuer ?? DEFAULT_CONVEX_TOKEN_ISSUER,
|
|
16
|
+
jwks,
|
|
17
|
+
algorithm: "RS256"
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async function getLensAccount(ctx) {
|
|
21
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
22
|
+
const address = identity?.subject;
|
|
23
|
+
return address && ADDRESS_RE.test(address) ? address.toLowerCase() : null;
|
|
24
|
+
}
|
|
25
|
+
async function requireLensAccount(ctx, message = "Sign in with Lens to continue") {
|
|
26
|
+
const account = await getLensAccount(ctx);
|
|
27
|
+
if (!account) throw new ConvexError(message);
|
|
28
|
+
return account;
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
getLensAccount,
|
|
32
|
+
lensAuthProvider,
|
|
33
|
+
requireLensAccount
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/convex/index.ts"],"sourcesContent":["import { ConvexError } from \"convex/values\"\nimport type { Auth } from \"convex/server\"\nimport { ADDRESS_RE, DEFAULT_CONVEX_TOKEN_AUDIENCE, DEFAULT_CONVEX_TOKEN_ISSUER } from \"../core/constants\"\n\nexport type LensAuthProviderOptions = {\n /** Public key from `npx lens-convex-auth keys`. Defaults to process.env.CONVEX_AUTH_JWKS */\n jwks?: string\n /** Must match the server's `issuer` option */\n issuer?: string\n /** Must match the server's `audience` option */\n audience?: string\n}\n\n// The auth provider for convex/auth.config.ts. Convex then trusts the tokens your server issues after\n// verifying the caller's Lens ID token (createConvexTokenHandler); their subject is the Lens account.\n// export default { providers: [lensAuthProvider({ jwks: process.env.CONVEX_AUTH_JWKS })] }\nexport function lensAuthProvider(options: LensAuthProviderOptions = {}) {\n const jwks = options.jwks ?? process.env.CONVEX_AUTH_JWKS\n if (!jwks) throw new Error(\"lens-convex-auth: set CONVEX_AUTH_JWKS on your Convex deployment\")\n return {\n type: \"customJwt\" as const,\n applicationID: options.audience ?? DEFAULT_CONVEX_TOKEN_AUDIENCE,\n issuer: options.issuer ?? DEFAULT_CONVEX_TOKEN_ISSUER,\n jwks,\n algorithm: \"RS256\" as const,\n }\n}\n\n// The Lens account the caller signed in as (lowercased address), or null when signed out.\nexport async function getLensAccount(ctx: { auth: Auth }): Promise<string | null> {\n const identity = await ctx.auth.getUserIdentity()\n const address = identity?.subject\n return address && ADDRESS_RE.test(address) ? address.toLowerCase() : null\n}\n\n// Like getLensAccount, but throws a ConvexError when the caller isn't signed in with Lens.\nexport async function requireLensAccount(ctx: { auth: Auth }, message = \"Sign in with Lens to continue\"): Promise<string> {\n const account = await getLensAccount(ctx)\n if (!account) throw new ConvexError(message)\n return account\n}\n"],"mappings":";;;;;;;AAAA,SAAS,mBAAmB;AAgBrB,SAAS,iBAAiB,UAAmC,CAAC,GAAG;AACtE,QAAM,OAAO,QAAQ,QAAQ,QAAQ,IAAI;AACzC,MAAI,CAAC,KAAM,OAAM,IAAI,MAAM,kEAAkE;AAC7F,SAAO;AAAA,IACL,MAAM;AAAA,IACN,eAAe,QAAQ,YAAY;AAAA,IACnC,QAAQ,QAAQ,UAAU;AAAA,IAC1B;AAAA,IACA,WAAW;AAAA,EACb;AACF;AAGA,eAAsB,eAAe,KAA6C;AAChF,QAAM,WAAW,MAAM,IAAI,KAAK,gBAAgB;AAChD,QAAM,UAAU,UAAU;AAC1B,SAAO,WAAW,WAAW,KAAK,OAAO,IAAI,QAAQ,YAAY,IAAI;AACvE;AAGA,eAAsB,mBAAmB,KAAqB,UAAU,iCAAkD;AACxH,QAAM,UAAU,MAAM,eAAe,GAAG;AACxC,MAAI,CAAC,QAAS,OAAM,IAAI,YAAY,OAAO;AAC3C,SAAO;AACT;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { L as LensChallenge, a as LensAuth, T as TokenService, b as LensEnvironmentName } from './auth-Baitf7Ze.js';
|
|
2
|
+
export { C as CHALLENGE_MAX_AGE_MS, c as CHALLENGE_REFRESH_MS, d as LENS_CHAIN_IDS, e as LensAuthOptions, f as LensCredentials, g as LensLoginRole, h as LensSessionInfo, M as MessageSigner, i as TOKENS_CHANGED_EVENT, j as TokenData, k as createLensAuth, l as lensApiOrigin, o as opensWalletWithDeepLink, s as signLensChallenge } from './auth-Baitf7Ze.js';
|
|
3
|
+
import * as _lens_protocol_client from '@lens-protocol/client';
|
|
4
|
+
import { PublicClient, SessionClient, Account, IStorageProvider } from '@lens-protocol/client';
|
|
5
|
+
import { Wallet } from 'thirdweb/wallets';
|
|
6
|
+
import { Chain as Chain$1, WalletClient, Transport, Account as Account$1 } from 'viem';
|
|
7
|
+
import { Chain } from 'thirdweb/chains';
|
|
8
|
+
import { ThirdwebClient } from 'thirdweb';
|
|
9
|
+
|
|
10
|
+
declare class OnboardingError extends Error {
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
declare function createOnboardingClient(auth: LensAuth): PublicClient<_lens_protocol_client.Context>;
|
|
14
|
+
declare function requestOnboardingChallenge(auth: LensAuth, client: PublicClient, walletAddress: string): Promise<LensChallenge>;
|
|
15
|
+
declare function authenticateOnboarding(client: PublicClient, challenge: LensChallenge, signature: string): Promise<SessionClient>;
|
|
16
|
+
declare function usernameFormatError(localName: string): string | null;
|
|
17
|
+
declare function isUsernameTaken(auth: LensAuth, localName: string): Promise<boolean>;
|
|
18
|
+
declare function checkUsername(session: SessionClient, localName: string): Promise<string | null>;
|
|
19
|
+
type AccountProfile = {
|
|
20
|
+
name?: string;
|
|
21
|
+
bio?: string;
|
|
22
|
+
picture?: File | null;
|
|
23
|
+
};
|
|
24
|
+
declare function uploadAccountMetadata(auth: LensAuth, profile: AccountProfile): Promise<string>;
|
|
25
|
+
declare function createLensAccount(auth: LensAuth, session: SessionClient, wallet: Wallet, request: {
|
|
26
|
+
localName: string;
|
|
27
|
+
metadataUri: string;
|
|
28
|
+
}): Promise<Account>;
|
|
29
|
+
declare function signInToCreatedAccount(auth: LensAuth, session: SessionClient, accountAddress: string): Promise<void>;
|
|
30
|
+
|
|
31
|
+
declare class LensTokenStorage implements IStorageProvider {
|
|
32
|
+
private tokens;
|
|
33
|
+
private prefix;
|
|
34
|
+
constructor(tokens: TokenService, prefix: string);
|
|
35
|
+
private isCredentials;
|
|
36
|
+
private metadataKey;
|
|
37
|
+
private credentialsMetadata;
|
|
38
|
+
getItem(key: string): string | null;
|
|
39
|
+
setItem(key: string, value: string): void;
|
|
40
|
+
removeItem(key: string): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare function decodeJwtPayload(token: string): Record<string, unknown> | null;
|
|
44
|
+
declare function lensSessionFromIdToken(idToken: string): {
|
|
45
|
+
account: string;
|
|
46
|
+
sessionId: string;
|
|
47
|
+
} | null;
|
|
48
|
+
|
|
49
|
+
declare function lensThirdwebChain(environment: LensEnvironmentName, rpcUrl?: string): Chain;
|
|
50
|
+
declare function lensViemChain(environment: LensEnvironmentName): Chain$1;
|
|
51
|
+
declare function createLensWalletClient(opts: {
|
|
52
|
+
wallet: Wallet;
|
|
53
|
+
client: ThirdwebClient;
|
|
54
|
+
chain: Chain;
|
|
55
|
+
viemChain: Chain$1;
|
|
56
|
+
}): WalletClient<Transport, Chain$1, Account$1>;
|
|
57
|
+
|
|
58
|
+
export { type AccountProfile, LensAuth, LensChallenge, LensEnvironmentName, LensTokenStorage, OnboardingError, TokenService, authenticateOnboarding, checkUsername, createLensAccount, createLensWalletClient, createOnboardingClient, decodeJwtPayload, isUsernameTaken, lensSessionFromIdToken, lensThirdwebChain, lensViemChain, requestOnboardingChallenge, signInToCreatedAccount, uploadAccountMetadata, usernameFormatError };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
CHALLENGE_MAX_AGE_MS,
|
|
4
|
+
CHALLENGE_REFRESH_MS,
|
|
5
|
+
LENS_CHAIN_IDS,
|
|
6
|
+
LensTokenStorage,
|
|
7
|
+
OnboardingError,
|
|
8
|
+
TOKENS_CHANGED_EVENT,
|
|
9
|
+
TokenService,
|
|
10
|
+
authenticateOnboarding,
|
|
11
|
+
checkUsername,
|
|
12
|
+
createLensAccount,
|
|
13
|
+
createLensAuth,
|
|
14
|
+
createLensWalletClient,
|
|
15
|
+
createOnboardingClient,
|
|
16
|
+
decodeJwtPayload,
|
|
17
|
+
isUsernameTaken,
|
|
18
|
+
lensApiOrigin,
|
|
19
|
+
lensSessionFromIdToken,
|
|
20
|
+
lensThirdwebChain,
|
|
21
|
+
lensViemChain,
|
|
22
|
+
opensWalletWithDeepLink,
|
|
23
|
+
requestOnboardingChallenge,
|
|
24
|
+
signInToCreatedAccount,
|
|
25
|
+
signLensChallenge,
|
|
26
|
+
uploadAccountMetadata,
|
|
27
|
+
usernameFormatError
|
|
28
|
+
} from "./chunk-2UCSL2CL.js";
|
|
29
|
+
export {
|
|
30
|
+
CHALLENGE_MAX_AGE_MS,
|
|
31
|
+
CHALLENGE_REFRESH_MS,
|
|
32
|
+
LENS_CHAIN_IDS,
|
|
33
|
+
LensTokenStorage,
|
|
34
|
+
OnboardingError,
|
|
35
|
+
TOKENS_CHANGED_EVENT,
|
|
36
|
+
TokenService,
|
|
37
|
+
authenticateOnboarding,
|
|
38
|
+
checkUsername,
|
|
39
|
+
createLensAccount,
|
|
40
|
+
createLensAuth,
|
|
41
|
+
createLensWalletClient,
|
|
42
|
+
createOnboardingClient,
|
|
43
|
+
decodeJwtPayload,
|
|
44
|
+
isUsernameTaken,
|
|
45
|
+
lensApiOrigin,
|
|
46
|
+
lensSessionFromIdToken,
|
|
47
|
+
lensThirdwebChain,
|
|
48
|
+
lensViemChain,
|
|
49
|
+
opensWalletWithDeepLink,
|
|
50
|
+
requestOnboardingChallenge,
|
|
51
|
+
signInToCreatedAccount,
|
|
52
|
+
signLensChallenge,
|
|
53
|
+
uploadAccountMetadata,
|
|
54
|
+
usernameFormatError
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Account } from 'thirdweb/wallets';
|
|
3
|
+
import { ConvexReactClient } from 'convex/react';
|
|
4
|
+
import { a as LensAuth } from '../auth-Baitf7Ze.js';
|
|
5
|
+
import { ConnectButtonProps } from 'thirdweb/react';
|
|
6
|
+
import '@lens-protocol/client';
|
|
7
|
+
import 'thirdweb/chains';
|
|
8
|
+
import 'thirdweb';
|
|
9
|
+
import 'viem';
|
|
10
|
+
|
|
11
|
+
type SignedInAccount = {
|
|
12
|
+
/** Lens account address, lowercased */
|
|
13
|
+
address: string;
|
|
14
|
+
/** Lens username (local name), when known */
|
|
15
|
+
username: string | null;
|
|
16
|
+
};
|
|
17
|
+
type LensAuthStatus =
|
|
18
|
+
/** Reading the stored session (first render, and during SSR) */
|
|
19
|
+
"loading"
|
|
20
|
+
/** No wallet and no Lens session */
|
|
21
|
+
| "signed-out"
|
|
22
|
+
/** Wallet connected, no Lens account signed in yet: the account dialog is open */
|
|
23
|
+
| "choosing-account"
|
|
24
|
+
/** Signed in to a Lens account (Convex is authenticated as it too) */
|
|
25
|
+
| "signed-in";
|
|
26
|
+
type LensAuthContextValue = {
|
|
27
|
+
auth: LensAuth;
|
|
28
|
+
status: LensAuthStatus;
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
isSignedIn: boolean;
|
|
31
|
+
/** The connected thirdweb wallet account */
|
|
32
|
+
wallet: Account | undefined;
|
|
33
|
+
/** The signed-in Lens account */
|
|
34
|
+
account: SignedInAccount | null;
|
|
35
|
+
/** Ends the Lens session and disconnects the wallet */
|
|
36
|
+
signOut: () => Promise<void>;
|
|
37
|
+
/** Opens the account dialog, e.g. to switch to another account */
|
|
38
|
+
openAccountDialog: () => void;
|
|
39
|
+
};
|
|
40
|
+
declare function useLensAuth(): LensAuthContextValue;
|
|
41
|
+
type LensAuthProviderProps = {
|
|
42
|
+
/** From createLensAuth(), created once at module level */
|
|
43
|
+
auth: LensAuth;
|
|
44
|
+
/** Your ConvexReactClient. Omit to use the package without Convex. */
|
|
45
|
+
convex?: ConvexReactClient;
|
|
46
|
+
/**
|
|
47
|
+
* Called after the user signs in from the account dialog (picking an account or creating one), once
|
|
48
|
+
* Convex accepts the session. A good place to create the user's row: `convex.mutation(api.users.ensure)`
|
|
49
|
+
*/
|
|
50
|
+
onSignIn?: (account: SignedInAccount) => void | Promise<void>;
|
|
51
|
+
/** Render the account dialog. Set to false to render <AccountDialog /> yourself. Defaults to true. */
|
|
52
|
+
accountDialog?: boolean;
|
|
53
|
+
children: React.ReactNode;
|
|
54
|
+
};
|
|
55
|
+
declare function LensAuthProvider({ auth, convex, onSignIn, accountDialog, children }: LensAuthProviderProps): React.JSX.Element;
|
|
56
|
+
|
|
57
|
+
type SignInButtonProps = {
|
|
58
|
+
/** Defaults to "Sign in" */
|
|
59
|
+
label?: React.ReactNode;
|
|
60
|
+
/** Defaults to "Logout" */
|
|
61
|
+
signOutLabel?: React.ReactNode;
|
|
62
|
+
/** thirdweb modal theme. Defaults to the page's theme (a `dark` class on <html>, or the system's). */
|
|
63
|
+
theme?: "light" | "dark";
|
|
64
|
+
/** Classes for the placeholder and sign-out buttons. Size the button's wrapper to size them all alike. */
|
|
65
|
+
className?: string;
|
|
66
|
+
/** Extra props for thirdweb's ConnectButton (wallets, connectModal, ...) */
|
|
67
|
+
connectButtonProps?: Partial<Omit<ConnectButtonProps, "client" | "chain" | "theme">>;
|
|
68
|
+
};
|
|
69
|
+
declare function SignInButton({ label, signOutLabel, theme, className, connectButtonProps }: SignInButtonProps): React.JSX.Element;
|
|
70
|
+
|
|
71
|
+
declare function AccountDialog(): React.JSX.Element;
|
|
72
|
+
|
|
73
|
+
type CreatedAccount = {
|
|
74
|
+
address: string;
|
|
75
|
+
localName: string;
|
|
76
|
+
};
|
|
77
|
+
declare function CreateAccountForm({ ownerAddress, onCreated, onBack }: {
|
|
78
|
+
ownerAddress: string;
|
|
79
|
+
onCreated: (account: CreatedAccount) => Promise<void>;
|
|
80
|
+
onBack?: () => void;
|
|
81
|
+
}): React.JSX.Element;
|
|
82
|
+
|
|
83
|
+
export { AccountDialog, CreateAccountForm, type CreatedAccount, type LensAuthContextValue, LensAuthProvider, type LensAuthProviderProps, type LensAuthStatus, SignInButton, type SignInButtonProps, type SignedInAccount, useLensAuth };
|