Skip to main content
1

Setup Better Auth with Next.js

First, follow the complete Better Auth Next.js Quickstart Guide to set up your Better Auth project and Next.js integration. Then proceed to Better Auth Basic Usage to learn how to create your login and sign up pages.This will guide you through:
  • Creating Better Auth Tables and Schemas
  • Setting up your Next.js app with Better Auth
  • Configuring environment variables
  • Creating auth.ts, mounting the handler and client instance
  • Creating login and sign up pages ready to receive new users 🎉
Come back here once you’ve completed the Better Auth setup!
2

Setup the Better Auth JWT Plugin

  1. In your auth.ts file add the following configuration:
  1. Migrate or generate your database:
npx @better-auth/cli migrate
Note: Before proceeding, check the Better Auth CLI Docs to determine which CLI commands and setup fit your specific use case best.
3

Create an auth-client.ts

You need to create an auth-client.ts - required for client side JWT functionality
4

Create API route handler

Create a new route.ts file under /api/[...all]/route.ts with the following content.
5

Create a use-better-auth.ts for getting JWTs and Deploy your app

  1. Deploy your app, then add your deployed application URL to your environment variables:
6

Install the Chipi SDK

First, install the required packages:
7

Setup the Chipi SDK Provider

  1. In your .env file, add your Chipi API keys:
  1. Set up the Chipi Pay provider in your application:
8

Add your JWKs Endpoint Url to Chipi 🕺 !

Visit the dashboard JWKS and JWT configuration, select Better Auth as your auth provider and paste your JWKS Endpoint URL.
Note: You do not need to manually create this /api/auth/jwks endpoint!
It is automatically provided by the Better Auth JWT plugin and handled internally by the catch-all route handler. Remember to replace https://my-deployed-app-domain.com with the actual URL of where your app is deployed.
9

Using Better Auth with Chipi hooks 🕺 !

Below you will see a simple example of how you can get and pass your tokens to the different Chipi hooks:
Note: If you have not yet created a wallet, you may see an error with a message like:message:“Wallet not found for externalUserId: user_id, apiPublicKey: pk_prod_something”This error is expected and shows that your app is correctly contacting Chipi, but there is not yet a wallet for this user. Once you create a wallet, this error will disappear.
10

Celebrate & Learn More!

That’s it! You should now have an initial working version of Chipi Pay integrated into your application. You can now start implementing various features like:
  • Wallet Creations
  • Sending tokens
  • Signing transactions
  • and more!
Need help? Check out our Telegram Community for support and to connect with other developers.