| 1208 | } |
| 1209 | |
| 1210 | func (c *connection) InsertUserAuthToken(ctx context.Context, opts *database.InsertUserAuthTokenOptions) (*database.UserAuthToken, error) { |
| 1211 | if err := database.Validate(opts); err != nil { |
| 1212 | return nil, err |
| 1213 | } |
| 1214 | |
| 1215 | res := &database.UserAuthToken{} |
| 1216 | err := c.getDB(ctx).QueryRowxContext(ctx, ` |
| 1217 | INSERT INTO user_auth_tokens (id, secret_hash, user_id, display_name, auth_client_id, representing_user_id, refresh, expires_on) |
| 1218 | VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *`, |
| 1219 | opts.ID, opts.SecretHash, opts.UserID, opts.DisplayName, opts.AuthClientID, opts.RepresentingUserID, opts.Refresh, opts.ExpiresOn, |
| 1220 | ).StructScan(res) |
| 1221 | if err != nil { |
| 1222 | return nil, parseErr("auth token", err) |
| 1223 | } |
| 1224 | return res, nil |
| 1225 | } |
| 1226 | |
| 1227 | func (c *connection) UpdateUserAuthTokenUsedOn(ctx context.Context, ids []string) error { |
| 1228 | _, err := c.getDB(ctx).ExecContext(ctx, "UPDATE user_auth_tokens SET used_on=now() WHERE id=ANY($1)", ids) |