MCPcopy Create free account
hub / github.com/async-labs/async / registerOrLogIn

Method registerOrLogIn

api/server/models/User.ts:502–655  ·  view source on GitHub ↗
({ uid, email, isLoginEvent, teamId })

Source from the content-addressed store, hash-verified

500 }
501
502 public static async registerOrLogIn({ uid, email, isLoginEvent, teamId }) {
503 const user = await this.findOne({ email }).setOptions({ lean: true });
504
505 let template;
506
507 if (user && isLoginEvent) {
508 if (!teamId) {
509 return user;
510 }
511
512 // teamId is truthy means this is an invitation event
513 // teamId is truthy means user has teamsForTeamMember
514
515 const team = user.teamsForTeamMember.find((team) => {
516 return team.teamId === teamId;
517 });
518
519 let updatedUser = user;
520
521 if (team && team.status === 'invited') {
522 // tested
523 updatedUser = await this.findOneAndUpdate(
524 { email, 'teamsForTeamMember.teamId': teamId },
525 {
526 $set: {
527 'teamsForTeamMember.$.status': 'team-member',
528 'teamsForTeamMember.$.joinedAt': new Date(),
529 'teamsForTeamMember.$.trialPeriodStartDate': team.trialPeriodStartDate,
530 'teamsForTeamMember.$.isSubscriptionActiveForTeam': team.isSubscriptionActiveForTeam,
531 'teamsForTeamMember.$.isPaymentFailedForTeam': team.isPaymentFailedForTeam,
532 },
533 defaultTeamId: !user.defaultTeamId ? teamId : user.defaultTeamId,
534 },
535 { runValidators: true, new: true },
536 ).setOptions({ lean: true });
537
538 const teamLeader = await this.findOne({ 'teamsForTeamLeader.teamId': teamId }).setOptions({
539 lean: true,
540 });
541
542 // update numberOfUniqueActiveTeamMembers
543 const updatedTeamLeader = await this.findOneAndUpdate(
544 { 'teamsForTeamLeader.teamId': teamId },
545 {
546 $inc: {
547 numberOfUniqueActiveTeamMembers: 1,
548 },
549 },
550 { runValidators: true, new: true },
551 );
552
553 const { isSubscriptionActiveForAccount, isTrialPeriodOverForAccount } =
554 await this.getSubscriptionStatus(teamLeader._id.toString());
555
556 if (isTrialPeriodOverForAccount && !isSubscriptionActiveForAccount) {
557 throw new Error(
558 'Associated account is not subscribed to a paid plan or free trial period is over.',
559 );

Callers

nothing calls this directly

Calls 6

getSubscriptionStatusMethod · 0.95
publicFieldsMethod · 0.95
retrieveSubscriptionFunction · 0.90
updateSubscriptionFunction · 0.90
getEmailTemplateFunction · 0.85
sendEmailFunction · 0.85

Tested by

no test coverage detected