phoenix/backend/db.go
Ivan R. 2c08171c7a
Start using JWT tokens
I thought this was a good idea.
Pros: fewer database calls.
Cons: there is no way to revoke the token (except for changing the secret key).

I rewrote the authorization as a middleware. Request handlers no longer need to validate the user.
2023-07-22 13:42:43 +05:00

20 lines
368 B
Go

package backend
import (
"github.com/ordinary-dev/phoenix/config"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func GetDatabaseConnection(cfg *config.Config) (*gorm.DB, error) {
db, err := gorm.Open(sqlite.Open(cfg.DBPath), &gorm.Config{})
if err != nil {
return nil, err
}
// Migrate the schema
db.AutoMigrate(&Admin{}, &Group{}, &Link{})
return db, nil
}