Monorepo for Tangled tangled.org

appview/oauth: create tangled profile on first login #1010

merged opened by anirudh.fi targeting master from icy/tolqpt

Creates an empty sh.tangled.actor.profile on first login. This should prevent profile picture uploads from breaking due to profile record existing beforehand.

This should also allow for us to estimate total users better globally.

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

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:hwevmowznbiukdf6uk5dwrrq/sh.tangled.repo.pull/3mcyvm2bhkj22
+43
Diff #0
+43
appview/oauth/handler.go
··· 10 10 "slices" 11 11 "time" 12 12 13 + comatproto "github.com/bluesky-social/indigo/api/atproto" 13 14 "github.com/bluesky-social/indigo/atproto/auth/oauth" 15 + lexutil "github.com/bluesky-social/indigo/lex/util" 14 16 "github.com/go-chi/chi/v5" 15 17 "github.com/posthog/posthog-go" 16 18 "tangled.org/core/api/tangled" ··· 82 84 } 83 85 84 86 o.Logger.Debug("session saved successfully") 87 + 85 88 go o.addToDefaultKnot(sessData.AccountDID.String()) 86 89 go o.addToDefaultSpindle(sessData.AccountDID.String()) 90 + go o.ensureTangledProfile(sessData) 87 91 88 92 if !o.Config.Core.Dev { 89 93 err = o.Posthog.Enqueue(posthog.Capture{ ··· 189 193 l.Debug("successfully addeds to default Knot") 190 194 } 191 195 196 + func (o *OAuth) ensureTangledProfile(sessData *oauth.ClientSessionData) { 197 + ctx := context.Background() 198 + did := sessData.AccountDID.String() 199 + l := o.Logger.With("did", did) 200 + 201 + sess, err := o.ClientApp.ResumeSession(ctx, sessData.AccountDID, sessData.SessionID) 202 + if err != nil { 203 + l.Error("failed to resume session for profile creation", "err", err) 204 + return 205 + } 206 + client := sess.APIClient() 207 + 208 + getRecordResp, err := comatproto.RepoGetRecord(ctx, client, "", tangled.ActorProfileNSID, did, "self") 209 + if err == nil && getRecordResp != nil { 210 + l.Debug("profile already exists") 211 + return 212 + } 213 + 214 + l.Debug("creating empty Tangled profile") 215 + 216 + emptyProfile := &tangled.ActorProfile{ 217 + LexiconTypeID: tangled.ActorProfileNSID, 218 + } 219 + 220 + _, err = comatproto.RepoPutRecord(ctx, client, &comatproto.RepoPutRecord_Input{ 221 + Collection: tangled.ActorProfileNSID, 222 + Repo: did, 223 + Rkey: "self", 224 + Record: &lexutil.LexiconTypeDecoder{Val: emptyProfile}, 225 + }) 226 + 227 + if err != nil { 228 + l.Error("failed to create empty profile", "err", err) 229 + return 230 + } 231 + 232 + l.Debug("successfully created empty Tangled profile") 233 + } 234 + 192 235 // create a session using apppasswords 193 236 type session struct { 194 237 AccessJwt string `json:"accessJwt"`

History

3 rounds 3 comments
sign up or login to add to the discussion
1 commit
expand
appview/oauth: create tangled profile on first login
3/3 success
expand
expand 1 comment

this change lgtm! will test out the whole thing.

pull request successfully merged
1 commit
expand
appview/oauth: create tangled profile on first login
3/3 success
expand
expand 1 comment

Makes sense, done.

anirudh.fi submitted #0
1 commit
expand
appview/oauth: create tangled profile on first login
expand 1 comment

do we need this? would have thought just new(tangled.ActorProfile) or &tangled.ActorProfile{} would suffice.

i would also suggest that we do this:

  • change the existence check to look in the DB instead of the user's PDS
  • if not present, putRecord in the PDS as well as insert an empty record in the DB

this way the existence check, upon login, is much faster.