MCPcopy Create free account
hub / github.com/supabase/auth / FindAllSessionsForUser

Function FindAllSessionsForUser

internal/models/sessions.go:325–347  ·  view source on GitHub ↗

FindAllSessionsForUser finds all of the sessions for a user. If forUpdate is set, it will first lock on the user row which can be used to prevent issues with concurrency. If the lock is acquired, it will return a UserNotFoundError and the operation should be retried. If there are no sessions for the

(tx *storage.Connection, userId uuid.UUID, forUpdate bool)

Source from the content-addressed store, hash-verified

323// UserNotFoundError and the operation should be retried. If there are no
324// sessions for the user, a nil result is returned without an error.
325func FindAllSessionsForUser(tx *storage.Connection, userId uuid.UUID, forUpdate bool) ([]*Session, error) {
326 if forUpdate {
327 user := &User{}
328 if err := tx.RawQuery(fmt.Sprintf("SELECT id FROM %q WHERE id = ? LIMIT 1 FOR UPDATE SKIP LOCKED;", user.TableName()), userId).First(user); err != nil {
329 if errors.Cause(err) == sql.ErrNoRows {
330 return nil, UserNotFoundError{}
331 }
332
333 return nil, err
334 }
335 }
336
337 var sessions []*Session
338 if err := tx.Where("user_id = ?", userId).All(&sessions); err != nil {
339 if errors.Cause(err) == sql.ErrNoRows {
340 return nil, nil
341 }
342
343 return nil, err
344 }
345
346 return sessions, nil
347}
348
349func updateFactorAssociatedSessions(tx *storage.Connection, userID, factorID uuid.UUID, aal string) error {
350 return tx.RawQuery("UPDATE "+(&pop.Model{Value: Session{}}).TableName()+" set aal = ?, factor_id = ? WHERE user_id = ? AND factor_id = ?", aal, nil, userID, factorID).Exec()

Callers 1

RefreshTokenGrantMethod · 0.92

Calls 2

TableNameMethod · 0.95
CauseMethod · 0.65

Tested by

no test coverage detected