zdravko/internal/server/services/oauth2_state.go

31 lines
745 B
Go
Raw Normal View History

2024-02-27 11:04:05 +00:00
package services
import (
"context"
"github.com/mentos1386/zdravko/database/models"
2024-02-27 11:04:05 +00:00
"github.com/jmoiron/sqlx"
)
func CreateOAuth2State(ctx context.Context, db *sqlx.DB, oauth2State *models.OAuth2State) error {
_, err := db.NamedExecContext(ctx,
"INSERT INTO oauth2_states (state, expires_at) VALUES (:state, :expires_at)",
oauth2State,
)
return err
}
func DeleteOAuth2State(ctx context.Context, db *sqlx.DB, state string) (deleted bool, err error) {
res, err := db.ExecContext(ctx, "DELETE FROM oauth2_states WHERE state = $1 AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ')", state)
2024-02-27 11:04:05 +00:00
if err != nil {
return false, err
}
affected, err := res.RowsAffected()
if err != nil {
return false, err
}
return affected > 0, err
}