feat: account connect

This commit is contained in:
Krispire Admin
2026-06-02 22:54:41 +05:30
parent cf3a49458a
commit 3f6b7b6636
8 changed files with 429 additions and 22 deletions
+25
View File
@@ -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.