···99 "log/slog"
1010 "net/http"
1111 "slices"
1212+ "strings"
1213 "time"
13141415 comatproto "github.com/bluesky-social/indigo/api/atproto"
···9192 go o.addToDefaultKnot(sessData.AccountDID.String())
9293 go o.addToDefaultSpindle(sessData.AccountDID.String())
9394 go o.ensureTangledProfile(sessData)
9595+ go o.autoClaimTnglShDomain(sessData.AccountDID.String())
94969597 if !o.Config.Core.Dev {
9698 err = o.Posthog.Enqueue(posthog.Capture{
···358360 }
359361360362 return nil
363363+}
364364+365365+// autoClaimTnglShDomain checks if the user has a .tngl.sh handle and, if so,
366366+// ensures their corresponding sites domain is claimed. This is idempotent —
367367+// ClaimDomain is a no-op if the claim already exists.
368368+func (o *OAuth) autoClaimTnglShDomain(did string) {
369369+ l := o.Logger.With("did", did)
370370+371371+ pdsDomain := strings.TrimPrefix(o.Config.Pds.Host, "https://")
372372+ pdsDomain = strings.TrimPrefix(pdsDomain, "http://")
373373+374374+ resolved, err := o.IdResolver.ResolveIdent(context.Background(), did)
375375+ if err != nil {
376376+ l.Error("autoClaimTnglShDomain: failed to resolve ident", "err", err)
377377+ return
378378+ }
379379+380380+ handle := resolved.Handle.String()
381381+ if !strings.HasSuffix(handle, "."+pdsDomain) {
382382+ return
383383+ }
384384+385385+ if err := db.ClaimDomain(o.Db, did, handle); err != nil {
386386+ l.Warn("autoClaimTnglShDomain: failed to claim domain", "domain", handle, "err", err)
387387+ } else {
388388+ l.Info("autoClaimTnglShDomain: claimed domain", "domain", handle)
389389+ }
361390}
362391363392// getAppPasswordSession returns a cached AppPasswordSession, creating one if needed.
+18
appview/signup/signup.go
···311311 }
312312 emailAdded = true
313313314314+ // step 4: auto-claim <username>.<pds-domain> for this user.
315315+ // All signups through this flow receive a <username>.tngl.sh handle
316316+ // (or whatever the configured PDS host is), so we claim the matching
317317+ // sites subdomain on their behalf. This is the only way to obtain a
318318+ // *.tngl.sh sites domain; it cannot be claimed manually via settings.
319319+ pdsDomain := strings.TrimPrefix(s.config.Pds.Host, "https://")
320320+ pdsDomain = strings.TrimPrefix(pdsDomain, "http://")
321321+ autoClaimDomain := username + "." + pdsDomain
322322+ if err := db.ClaimDomain(s.db, did, autoClaimDomain); err != nil {
323323+ s.l.Warn("failed to auto-claim sites domain at signup",
324324+ "domain", autoClaimDomain,
325325+ "did", did,
326326+ "error", err,
327327+ )
328328+ } else {
329329+ s.l.Info("auto-claimed sites domain at signup", "domain", autoClaimDomain, "did", did)
330330+ }
331331+314332 // if we get here, we've successfully created the account and added the email
315333 success = true
316334