feat: account connect
This commit is contained in:
@@ -44,6 +44,31 @@ func (r *OAuthAccountRepo) FindByProvider(ctx context.Context, provider, provide
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// ListProvidersForUser returns the distinct provider names linked to this
|
||||
// user, ordered alphabetically. Used by the settings UI to mark each
|
||||
// social-connect row as "Connected" vs "Connect".
|
||||
func (r *OAuthAccountRepo) ListProvidersForUser(ctx context.Context, userID string) ([]string, error) {
|
||||
const q = `
|
||||
SELECT DISTINCT provider
|
||||
FROM oauth_accounts
|
||||
WHERE user_id = $1
|
||||
ORDER BY provider`
|
||||
rows, err := r.pg.Pool.Query(ctx, q, userID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list oauth providers: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []string{}
|
||||
for rows.Next() {
|
||||
var p string
|
||||
if err := rows.Scan(&p); err != nil {
|
||||
return nil, fmt.Errorf("scan oauth provider: %w", err)
|
||||
}
|
||||
out = append(out, p)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// Link inserts a new oauth_accounts row tying a provider identity to an
|
||||
// existing user. Idempotent: a second call for the same (provider, sub)
|
||||
// returns the existing row instead of erroring on the unique constraint.
|
||||
|
||||
Reference in New Issue
Block a user