MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetAndDeleteWebRefreshToken

Method GetAndDeleteWebRefreshToken

backend/store/web_refresh_token.go:62–84  ·  view source on GitHub ↗

GetAndDeleteWebRefreshToken atomically retrieves and deletes a refresh token. Returns the token if found and deleted, nil if not found.

(ctx context.Context, tokenHash string)

Source from the content-addressed store, hash-verified

60// GetAndDeleteWebRefreshToken atomically retrieves and deletes a refresh token.
61// Returns the token if found and deleted, nil if not found.
62func (s *Store) GetAndDeleteWebRefreshToken(ctx context.Context, tokenHash string) (*WebRefreshTokenMessage, error) {
63 q := qb.Q().Space(`
64 DELETE FROM web_refresh_token
65 WHERE token_hash = ?
66 RETURNING token_hash, user_email, expires_at
67 `, tokenHash)
68
69 query, args, err := q.ToSQL()
70 if err != nil {
71 return nil, err
72 }
73
74 msg := &WebRefreshTokenMessage{}
75 if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan(
76 &msg.TokenHash, &msg.UserEmail, &msg.ExpiresAt,
77 ); err != nil {
78 if errors.Is(err, sql.ErrNoRows) {
79 return nil, nil
80 }
81 return nil, errors.Wrap(err, "failed to get and delete web refresh token")
82 }
83 return msg, nil
84}
85
86func (s *Store) DeleteWebRefreshToken(ctx context.Context, tokenHash string) error {
87 q := qb.Q().Space(`

Callers 2

RefreshMethod · 0.80

Calls 5

GetDBMethod · 0.95
QFunction · 0.92
SpaceMethod · 0.80
ToSQLMethod · 0.80
ScanMethod · 0.80

Tested by

no test coverage detected