Monorepo for Tangled tangled.org

appview/signup: auto-claim pds handle domain at signup

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>

anirudh.fi 9cb6dc86 b8c5e804

verified
+47
+29
appview/oauth/handler.go
··· 9 9 "log/slog" 10 10 "net/http" 11 11 "slices" 12 + "strings" 12 13 "time" 13 14 14 15 comatproto "github.com/bluesky-social/indigo/api/atproto" ··· 91 92 go o.addToDefaultKnot(sessData.AccountDID.String()) 92 93 go o.addToDefaultSpindle(sessData.AccountDID.String()) 93 94 go o.ensureTangledProfile(sessData) 95 + go o.autoClaimTnglShDomain(sessData.AccountDID.String()) 94 96 95 97 if !o.Config.Core.Dev { 96 98 err = o.Posthog.Enqueue(posthog.Capture{ ··· 411 413 } 412 414 413 415 return nil 416 + } 417 + 418 + // autoClaimTnglShDomain checks if the user has a .tngl.sh handle and, if so, 419 + // ensures their corresponding sites domain is claimed. This is idempotent — 420 + // ClaimDomain is a no-op if the claim already exists. 421 + func (o *OAuth) autoClaimTnglShDomain(did string) { 422 + l := o.Logger.With("did", did) 423 + 424 + pdsDomain := strings.TrimPrefix(o.Config.Pds.Host, "https://") 425 + pdsDomain = strings.TrimPrefix(pdsDomain, "http://") 426 + 427 + resolved, err := o.IdResolver.ResolveIdent(context.Background(), did) 428 + if err != nil { 429 + l.Error("autoClaimTnglShDomain: failed to resolve ident", "err", err) 430 + return 431 + } 432 + 433 + handle := resolved.Handle.String() 434 + if !strings.HasSuffix(handle, "."+pdsDomain) { 435 + return 436 + } 437 + 438 + if err := db.ClaimDomain(o.Db, did, handle); err != nil { 439 + l.Warn("autoClaimTnglShDomain: failed to claim domain", "domain", handle, "err", err) 440 + } else { 441 + l.Info("autoClaimTnglShDomain: claimed domain", "domain", handle) 442 + } 414 443 } 415 444 416 445 // getAppPasswordSession returns a cached AppPasswordSession, creating one if needed.
+18
appview/signup/signup.go
··· 311 311 } 312 312 emailAdded = true 313 313 314 + // step 4: auto-claim <username>.<pds-domain> for this user. 315 + // All signups through this flow receive a <username>.tngl.sh handle 316 + // (or whatever the configured PDS host is), so we claim the matching 317 + // sites subdomain on their behalf. This is the only way to obtain a 318 + // *.tngl.sh sites domain; it cannot be claimed manually via settings. 319 + pdsDomain := strings.TrimPrefix(s.config.Pds.Host, "https://") 320 + pdsDomain = strings.TrimPrefix(pdsDomain, "http://") 321 + autoClaimDomain := username + "." + pdsDomain 322 + if err := db.ClaimDomain(s.db, did, autoClaimDomain); err != nil { 323 + s.l.Warn("failed to auto-claim sites domain at signup", 324 + "domain", autoClaimDomain, 325 + "did", did, 326 + "error", err, 327 + ) 328 + } else { 329 + s.l.Info("auto-claimed sites domain at signup", "domain", autoClaimDomain, "did", did) 330 + } 331 + 314 332 // if we get here, we've successfully created the account and added the email 315 333 success = true 316 334