MCPcopy Create free account
hub / github.com/algolia/cli / identifyNewlyAuthenticatedUser

Function identifyNewlyAuthenticatedUser

pkg/cmd/root/root.go:265–285  ·  view source on GitHub ↗

identifyNewlyAuthenticatedUser re-sends an Identify when the user signed in during the command (e.g. `application create` while logged out): the Identify from PersistentPreRunE went out anonymous, so the identity would otherwise only ship on the next invocation. Runs before the deferred Command Comp

(ctx context.Context, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

263// otherwise only ship on the next invocation. Runs before the deferred
264// Command Completed so that event carries the user too.
265func identifyNewlyAuthenticatedUser(ctx context.Context, cmd *cobra.Command) {
266 if cmd == nil || !cmdutil.ShouldTrackUsage(cmd) {
267 return
268 }
269 // Same gating as trackCommandCompleted: an empty command path means
270 // PersistentPreRunE never ran, so no login could have happened either.
271 metadata := telemetry.GetEventMetadata(ctx)
272 if metadata == nil || metadata.CommandPath == "" || metadata.UserID != "" {
273 return
274 }
275 token := auth.LoadToken()
276 if token == nil || token.UserID == "" {
277 return
278 }
279 metadata.SetUser(token.UserID, token.Email, token.Name)
280 client := telemetry.GetTelemetryClient(ctx)
281 if client == nil {
282 return
283 }
284 _ = client.Identify(ctx)
285}
286
287// trackCommandCompleted reports how the command ended: success, failure (with
288// the class of the error) or user cancellation.

Callers 1

ExecuteFunction · 0.85

Calls 5

ShouldTrackUsageFunction · 0.92
GetEventMetadataFunction · 0.92
GetTelemetryClientFunction · 0.92
SetUserMethod · 0.80
IdentifyMethod · 0.65

Tested by

no test coverage detected