mirror of
https://github.com/1f349/lavender.git
synced 2024-12-21 23:24:09 +00:00
Allow tokens to be null
This commit is contained in:
parent
3a7eef803e
commit
c5a4d17a75
@ -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
|
||||
);
|
||||
|
@ -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"`
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
})
|
||||
}) {
|
||||
|
Loading…
Reference in New Issue
Block a user