How I implement auth with Go

Unlike other popular programming languages, Go doesn’t have any library to implement authentication. This unfortunately means that we have to design a micro service architecture.
Luckily, there are new services that allow us to easily achieve this goal. One being Supabase. This also doubles as a database along with an ORM which really relieves a lot of stress off my mind because there is no need to install and configure local services.
How to implement Supabase Auth in Go
First install the supabase-go library
go get github.com/nedpals/supabase-go
Then you can simply import the library and call the authentication functions in your handlers
package main
import (
"context"
"log"
"github.com/gofiber/fiber/v2"
supa "github.com/nedpals/supabase-go"
)
func main() {
supabaseUrl := "<SUPABASE-URL>"
supabaseKey := "<SUPABASE-KEY>"
supabase := supa.CreateClient(supabaseUrl, supabaseKey)
app := fiber.New()
app.Get("/register", func(c *fiber.Ctx) error {
user, err := supabase.Auth.SignUp(context.Background(), supa.UserCredentials{
Email: "[email protected]",
Password: "password",
})
if err != nil {
return err
}
})
app.Get("/login", func(c *fiber.Ctx) error {
user, err := supabase.Auth.SignIn(context.Background(), supa.UserCredentials{
Email: "[email protected]",
Password: "password",
})
if err != nil {
return err
}
})
log.Fatal(app.Listen(":3000"))
}DONE!
Now you have a full PostgreSQL database with backups, scaling, authentication and rapid development.
I love this solution because its just so simple and easy to implement. Even in frameworks such as Laravel where there has been a lot of work done in terms of authentication, it isn’t this simple. Javascript authentication libraries are also simple however from my experience the documentation takes a fair amount of time to read and then you don’t get to use GO!





