Monorepo for Tangled tangled.org

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

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

anirudh.fi a725309a 49959912

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{ ··· 358 360 } 359 361 360 362 return nil 363 + } 364 + 365 + // autoClaimTnglShDomain checks if the user has a .tngl.sh handle and, if so, 366 + // ensures their corresponding sites domain is claimed. This is idempotent — 367 + // ClaimDomain is a no-op if the claim already exists. 368 + func (o *OAuth) autoClaimTnglShDomain(did string) { 369 + l := o.Logger.With("did", did) 370 + 371 + pdsDomain := strings.TrimPrefix(o.Config.Pds.Host, "https://") 372 + pdsDomain = strings.TrimPrefix(pdsDomain, "http://") 373 + 374 + resolved, err := o.IdResolver.ResolveIdent(context.Background(), did) 375 + if err != nil { 376 + l.Error("autoClaimTnglShDomain: failed to resolve ident", "err", err) 377 + return 378 + } 379 + 380 + handle := resolved.Handle.String() 381 + if !strings.HasSuffix(handle, "."+pdsDomain) { 382 + return 383 + } 384 + 385 + if err := db.ClaimDomain(o.Db, did, handle); err != nil { 386 + l.Warn("autoClaimTnglShDomain: failed to claim domain", "domain", handle, "err", err) 387 + } else { 388 + l.Info("autoClaimTnglShDomain: claimed domain", "domain", handle) 389 + } 361 390 } 362 391 363 392 // 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