Allow tokens to be null

This commit is contained in:
Melon 2024-05-18 01:27:54 +01:00
parent 3a7eef803e
commit c5a4d17a75
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
4 changed files with 25 additions and 23 deletions

View File

@ -5,9 +5,9 @@ CREATE TABLE users
email_verified BOOLEAN DEFAULT 0 NOT NULL,
roles TEXT NOT NULL,
userinfo TEXT NOT NULL,
access_token TEXT NOT NULL,
refresh_token TEXT NOT NULL,
expiry DATETIME NOT NULL,
access_token TEXT,
refresh_token TEXT,
expiry DATETIME,
updated_at DATETIME NOT NULL,
active BOOLEAN DEFAULT 1 NOT NULL
);

View File

@ -5,6 +5,7 @@
package database
import (
"database/sql"
"time"
)
@ -21,14 +22,14 @@ type ClientStore struct {
}
type User struct {
Subject string `json:"subject"`
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
Roles string `json:"roles"`
Userinfo string `json:"userinfo"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
Expiry time.Time `json:"expiry"`
UpdatedAt time.Time `json:"updated_at"`
Active bool `json:"active"`
Subject string `json:"subject"`
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
Roles string `json:"roles"`
Userinfo string `json:"userinfo"`
AccessToken sql.NullString `json:"access_token"`
RefreshToken sql.NullString `json:"refresh_token"`
Expiry sql.NullTime `json:"expiry"`
UpdatedAt time.Time `json:"updated_at"`
Active bool `json:"active"`
}

View File

@ -7,6 +7,7 @@ package database
import (
"context"
"database/sql"
"time"
)
@ -97,9 +98,9 @@ LIMIT 1
`
type GetUserTokenRow struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
Expiry time.Time `json:"expiry"`
AccessToken sql.NullString `json:"access_token"`
RefreshToken sql.NullString `json:"refresh_token"`
Expiry sql.NullTime `json:"expiry"`
}
func (q *Queries) GetUserToken(ctx context.Context, subject string) (GetUserTokenRow, error) {
@ -155,10 +156,10 @@ WHERE subject = ?
`
type UpdateUserTokenParams struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
Expiry time.Time `json:"expiry"`
Subject string `json:"subject"`
AccessToken sql.NullString `json:"access_token"`
RefreshToken sql.NullString `json:"refresh_token"`
Expiry sql.NullTime `json:"expiry"`
Subject string `json:"subject"`
}
func (q *Queries) UpdateUserToken(ctx context.Context, arg UpdateUserTokenParams) error {

View File

@ -150,9 +150,9 @@ func (h *HttpServer) loginCallback(rw http.ResponseWriter, req *http.Request, _
if h.DbTx(rw, func(tx *database.Queries) error {
return tx.UpdateUserToken(req.Context(), database.UpdateUserTokenParams{
AccessToken: token.AccessToken,
RefreshToken: token.RefreshToken,
Expiry: token.Expiry,
AccessToken: sql.NullString{String: token.AccessToken, Valid: true},
RefreshToken: sql.NullString{String: token.RefreshToken, Valid: true},
Expiry: sql.NullTime{Time: token.Expiry, Valid: true},
Subject: auth.Subject,
})
}) {