This code will generate token for Local Development process with Turso. When you use turso-cli
or sqld
you need to generate database token to connect with your database remotely.
full_access_token
- Used to connect with database with full access moderead_only_token
- Use to connect with database with read access only modepublic_key_pem
andpublic_key_base64
- Use as decoding key in our server
Referring to Turso Docs - Local Development
It’s recommended to use environment variables for both url and authToken for a seamless developer experience.
Save the public_key_pem
and public_key_base64
in a file:
Filename: jwt_key.pem
for public_key_pem
-----BEGIN PUBLIC KEY-----
r9sVX1erm38EStmIHiKh5IvPqtrlUyTRn54s8xkMkdg=
-----END PUBLIC KEY-----
Filename: jwt_key.base64
for public_key_base64
r9sVX1erm38EStmIHiKh5IvPqtrlUyTRn54s8xkMkdg
SQLD_AUTH_JWT_KEY_FILE=/path/to/jwt_key.pem
or
sqld -d $(pwd)/local.db --http-listen-addr=127.0.0.1:8080 --enable-http-console --auth-jwt-key-file=./jwt_key.pem
turso dev --db-file local.db --auth-jwt-key-file /path/to/jwt_key.pem
TURSO_DATABASE_URL=127.0.0.0:8080
TURSO_AUTH_TOKEN=your-full-access-or-read-only-token-here
🥂