mirror of
https://github.com/1f349/lavender.git
synced 2024-12-22 07:34:06 +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,
|
email_verified BOOLEAN DEFAULT 0 NOT NULL,
|
||||||
roles TEXT NOT NULL,
|
roles TEXT NOT NULL,
|
||||||
userinfo TEXT NOT NULL,
|
userinfo TEXT NOT NULL,
|
||||||
access_token TEXT NOT NULL,
|
access_token TEXT,
|
||||||
refresh_token TEXT NOT NULL,
|
refresh_token TEXT,
|
||||||
expiry DATETIME NOT NULL,
|
expiry DATETIME,
|
||||||
updated_at DATETIME NOT NULL,
|
updated_at DATETIME NOT NULL,
|
||||||
active BOOLEAN DEFAULT 1 NOT NULL
|
active BOOLEAN DEFAULT 1 NOT NULL
|
||||||
);
|
);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,9 +27,9 @@ type User struct {
|
|||||||
EmailVerified bool `json:"email_verified"`
|
EmailVerified bool `json:"email_verified"`
|
||||||
Roles string `json:"roles"`
|
Roles string `json:"roles"`
|
||||||
Userinfo string `json:"userinfo"`
|
Userinfo string `json:"userinfo"`
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken sql.NullString `json:"access_token"`
|
||||||
RefreshToken string `json:"refresh_token"`
|
RefreshToken sql.NullString `json:"refresh_token"`
|
||||||
Expiry time.Time `json:"expiry"`
|
Expiry sql.NullTime `json:"expiry"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -97,9 +98,9 @@ LIMIT 1
|
|||||||
`
|
`
|
||||||
|
|
||||||
type GetUserTokenRow struct {
|
type GetUserTokenRow struct {
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken sql.NullString `json:"access_token"`
|
||||||
RefreshToken string `json:"refresh_token"`
|
RefreshToken sql.NullString `json:"refresh_token"`
|
||||||
Expiry time.Time `json:"expiry"`
|
Expiry sql.NullTime `json:"expiry"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetUserToken(ctx context.Context, subject string) (GetUserTokenRow, error) {
|
func (q *Queries) GetUserToken(ctx context.Context, subject string) (GetUserTokenRow, error) {
|
||||||
@ -155,9 +156,9 @@ WHERE subject = ?
|
|||||||
`
|
`
|
||||||
|
|
||||||
type UpdateUserTokenParams struct {
|
type UpdateUserTokenParams struct {
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken sql.NullString `json:"access_token"`
|
||||||
RefreshToken string `json:"refresh_token"`
|
RefreshToken sql.NullString `json:"refresh_token"`
|
||||||
Expiry time.Time `json:"expiry"`
|
Expiry sql.NullTime `json:"expiry"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,9 +150,9 @@ func (h *HttpServer) loginCallback(rw http.ResponseWriter, req *http.Request, _
|
|||||||
|
|
||||||
if h.DbTx(rw, func(tx *database.Queries) error {
|
if h.DbTx(rw, func(tx *database.Queries) error {
|
||||||
return tx.UpdateUserToken(req.Context(), database.UpdateUserTokenParams{
|
return tx.UpdateUserToken(req.Context(), database.UpdateUserTokenParams{
|
||||||
AccessToken: token.AccessToken,
|
AccessToken: sql.NullString{String: token.AccessToken, Valid: true},
|
||||||
RefreshToken: token.RefreshToken,
|
RefreshToken: sql.NullString{String: token.RefreshToken, Valid: true},
|
||||||
Expiry: token.Expiry,
|
Expiry: sql.NullTime{Time: token.Expiry, Valid: true},
|
||||||
Subject: auth.Subject,
|
Subject: auth.Subject,
|
||||||
})
|
})
|
||||||
}) {
|
}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user