Setting up Pocketbase

Setting up oauth , email smtp and dploying to hop.io

·

3 min read

Table of contents

The Basics

PocketBase is an open-source backend consisting of an embedded database (SQLite) with real-time subscriptions, built-in auth management, convenient dashboard UI and simple REST-ish API.

Why pocketbase?

  • auto-generates REST API's + real-time endpoints for all your tables, with auto-generated documentation

  • users table is a first-class citizen, with their collection type. you can easily create multiple user collections and manage them independently, the collections can also be easily referenced from other collections with the `relation` field

  • The best field relationship picker

  • rich text field

  • snappy admin UI

  • logs

  • file upload with S3 capabilities

  • backups with restore

  • upto 20 Oauth providers with a simple one-click OAuth API


   const authData = await pb.collection('users').authWithOAuth2({ provider: 'google' });
  • JS hooks: Pocketbase is written in GO and allows you to import it as a module in your existing GO project and use its exposed hooks that give you access to its internals. That was great but they made it even better by adding the ability to write hooks in javascript and not have to rebuild your project with every custom change

To get started, just download the appropriate binary ,unzip it and run ./pocketbase serve

tada:

To set up our Oauth providers we'll

Obtain client ID and client secret from the providers setting up GitHub OAUTH, setting up google OAUTH

visit your GitHub settings page, create a new app and fill in your details

then enable the respective providers in the Pocketbase admin dashboard settings>auth providers, and boom secure authentication enabled.

Most websites do provide good old password + email authentication and to make this easy we'll set up an email SMTP provider to enable activities like password reset and email confirmation which we don't have to worry about with the Oauth method

Pocketbase will still do email password authentication just fine without its email capabilities , you might even figure out a workaround an use an authenticator QR code to verify accounts with the JS hooks

To set-up our mail with SMTP we'll go to settings>mail-settings, we can either set an SMTP server or use a provider, am not good with the former so we'll use one of these recommended ones with generous free tier

i used brevo and you just have to create an account , and under SMTP and API generate a new SMTP key and copy the smtp server + login

In your pocketbase under settings>mail settings

the username -> Brevo SMTP login

the password -> Brevo SMTP key

hit save and test email.

and now you're ready for some awesome adventures

If you get stuck the pocketbase discussions are full of helpfull solutions to all kinds of issues