Set up wallet-based user authentication for notification inbox integration using JWT tokens and client keys
dk_...
X-Dialect-Client-Key
Authorization: Bearer
const prepareResponse = await fetch('https://alerts-api.dial.to/v2/auth/solana/prepare', { method: 'POST', headers: { 'X-Dialect-Client-Key': 'YOUR_CLIENT_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ walletAddress: 'USER_WALLET_ADDRESS' }) }); const { message } = await prepareResponse.json(); // Returns: { message: "Sign this message to authenticate. Nonce: 1638471298347" }
// Using @solana/wallet-adapter import { useWallet } from '@solana/wallet-adapter-react'; const { signMessage, publicKey } = useWallet(); const encodedMessage = new TextEncoder().encode(message); const signature = await signMessage(encodedMessage); const signatureBase58 = bs58.encode(signature);
const verifyResponse = await fetch('https://alerts-api.dial.to/v2/auth/solana/verify', { method: 'POST', headers: { 'X-Dialect-Client-Key': 'YOUR_CLIENT_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ message: message, signature: signatureBase58 }) }); const { token } = await verifyResponse.json(); // Store this JWT token for subsequent API calls // Note: JWT tokens have a 1 year lifetime
const response = await fetch('https://alerts-api.dial.to/v2/history', { headers: { 'Authorization': `Bearer ${jwtToken}`, 'X-Dialect-Client-Key': 'YOUR_CLIENT_KEY' } });
Was this page helpful?