···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{
···411413 }
412414413415 return nil
416416+}
417417+418418+// autoClaimTnglShDomain checks if the user has a .tngl.sh handle and, if so,
419419+// ensures their corresponding sites domain is claimed. This is idempotent —
420420+// ClaimDomain is a no-op if the claim already exists.
421421+func (o *OAuth) autoClaimTnglShDomain(did string) {
422422+ l := o.Logger.With("did", did)
423423+424424+ pdsDomain := strings.TrimPrefix(o.Config.Pds.Host, "https://")
425425+ pdsDomain = strings.TrimPrefix(pdsDomain, "http://")
426426+427427+ resolved, err := o.IdResolver.ResolveIdent(context.Background(), did)
428428+ if err != nil {
429429+ l.Error("autoClaimTnglShDomain: failed to resolve ident", "err", err)
430430+ return
431431+ }
432432+433433+ handle := resolved.Handle.String()
434434+ if !strings.HasSuffix(handle, "."+pdsDomain) {
435435+ return
436436+ }
437437+438438+ if err := db.ClaimDomain(o.Db, did, handle); err != nil {
439439+ l.Warn("autoClaimTnglShDomain: failed to claim domain", "domain", handle, "err", err)
440440+ } else {
441441+ l.Info("autoClaimTnglShDomain: claimed domain", "domain", handle)
442442+ }
414443}
415444416445// 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