• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-js / 6007676806

29 Aug 2023 03:54AM UTC coverage: 85.258% (-0.05%) from 85.311%
6007676806

push

github

Kenneth Geisshirt
Skip custom auth function tests

881 of 1096 branches covered (0.0%)

Branch coverage included in aggregate %.

2294 of 2628 relevant lines covered (87.29%)

796.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/packages/realm/src/app-services/EmailPasswordAuth.ts
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2022 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
import { binding } from "../internal";
20

21
/**
22
 * Authentication provider where users identify using email and password.
23
 * @see https://www.mongodb.com/docs/atlas/app-services/authentication/email-password/
24
 */
25
export class EmailPasswordAuth {
26
  /** @internal */
27
  public internal: binding.UsernamePasswordProviderClient;
28

29
  /** @internal */
30
  constructor(internal: binding.UsernamePasswordProviderClient) {
31
    this.internal = internal;
37✔
32
  }
33

34
  /**
35
   * Registers a new email identity with the email/password provider,
36
   * and sends a confirmation email to the provided address.
37
   * @param details - The new user's email and password details.
38
   * @param details.email - The email address of the user to register.
39
   * @param details.password - The password that the user created for the new username/password identity.
40
   * @since v10.10.0
41
   */
42
  public async registerUser(details: { email: string; password: string }) {
43
    await this.internal.registerEmail(details.email, details.password);
32✔
44
  }
45

46
  /**
47
   * Confirms an email identity with the email/password provider.
48
   * @param details - The received token and ID details
49
   * @param details.token - The confirmation token that was emailed to the user.
50
   * @param details.tokenId - The confirmation token id that was emailed to the user.
51
   * @since v10.10.0
52
   */
53
  public async confirmUser(details: { token: string; tokenId: string }) {
54
    await this.internal.confirmUser(details.token, details.tokenId);
1✔
55
  }
56

57
  /**
58
   * Re-sends a confirmation email to a user that has registered but
59
   * not yet confirmed their email address.
60
   * @param details - The associated email details.
61
   * @param details.email - The email address of the user to re-send a confirmation for.
62
   * @since v10.10.0
63
   */
64
  public async resendConfirmationEmail(details: { email: string }) {
65
    await this.internal.resendConfirmationEmail(details.email);
1✔
66
  }
67

68
  /**
69
   * Re-run the custom confirmation function for user that has registered but
70
   * not yet confirmed their email address.
71
   * @param details - The associated email details.
72
   * @param details.email - The email address of the user to re-run the confirmation for.
73
   * @since v10.10.0
74
   */
75
  public async retryCustomConfirmation(details: { email: string }) {
76
    await this.internal.retryCustomConfirmation(details.email);
1✔
77
  }
78

79
  /**
80
   * Resets the password of an email identity using the password reset token emailed to a user.
81
   * @param details - The token and password details for the reset.
82
   * @param details.password - The desired new password.
83
   * @param details.token - The password reset token that was emailed to the user.
84
   * @param details.tokenId - The password reset token id that was emailed to the user.
85
   * @since v10.10.0
86
   */
87
  public async resetPassword(details: { password: string; token: string; tokenId: string }) {
88
    await this.internal.resetPassword(details.password, details.token, details.tokenId);
×
89
  }
90

91
  /**
92
   * Sends an email to the user for resetting the password.
93
   * @param details - The email details to send the reset to.
94
   * @param details.email - The email address of the user to re-send a confirmation for.
95
   * @since v10.10.0
96
   */
97
  public async sendResetPasswordEmail(details: { email: string }) {
98
    await this.internal.sendResetPasswordEmail(details.email);
1✔
99
  }
100

101
  /**
102
   * Call the custom function to reset the password.
103
   * @param details - The new user's email and password details.
104
   * @param details.email - The email address of the user to register.
105
   * @param details.password - The password that the user created for the new username/password identity.
106
   * @param args One or more arguments to pass to the function.
107
   * @since v10.10.0
108
   */
109
  public async callResetPasswordFunction(details: { email: string; password: string }, ...args: unknown[]) {
110
    await this.internal.callResetPasswordFunction(details.email, details.password, args as binding.EJson[]);
×
111
  }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc