ContactChannel

ContactChannel represents a user’s contact information, such as an email address or phone number. Some auth methods, like OTP/magic link or password, use contact channels for authentication.

On this page:

ContactChannel

Basic information about a contact channel, as seen by a user themselves.

Usually obtained by calling user.[list|use]ContactChannels().

Table of Contents

1type ContactChannel = {
2 id: string; //$stack-link-to:#contactchannelid
3 value: string; //$stack-link-to:#contactchannelvalue
4 type: 'email'; //$stack-link-to:#contactchanneltype
5 isPrimary: boolean; //$stack-link-to:#contactchannelisprimary
6 isVerified: boolean; //$stack-link-to:#contactchannelisverified
7 usedForAuth: boolean; //$stack-link-to:#contactchannelusedforauth
8
9 sendVerificationEmail(): Promise<void>; //$stack-link-to:#contactchannelsendverificationemail
10 update(options): Promise<void>; //$stack-link-to:#contactchannelupdateoptions
11 delete(): Promise<void>; //$stack-link-to:#contactchanneldelete
12};

contactChannel.id

The id of the contact channel as a string.

Type Definition

1declare const id: string;

contactChannel.value

The value of the contact channel. If type is "email", this is an email address.

Type Definition

1declare const value: string;

contactChannel.type

The type of the contact channel. Currently always "email".

Type Definition

1declare const type: 'email';

contactChannel.isPrimary

Indicates whether the contact channel is the user’s primary contact channel. If an email is set to primary, it will be the value on the user.primaryEmail field.

Type Definition

1declare const isPrimary: boolean;

contactChannel.isVerified

Indicates whether the contact channel is verified.

Type Definition

1declare const isVerified: boolean;

contactChannel.usedForAuth

Indicates whether the contact channel is used for authentication. If set to true, the user can use this contact channel with OTP or password to sign in.

Type Definition

1declare const usedForAuth: boolean;

contactChannel.sendVerificationEmail()

Sends a verification email to this contact channel. Once the user clicks the verification link in the email, the contact channel will be marked as verified.

Parameters

None.

Returns

Promise<void>

Signature

1declare function sendVerificationEmail(): Promise<void>;

Examples

1await contactChannel.sendVerificationEmail();

contactChannel.update(options)

Updates the contact channel. After updating the value, the contact channel will be marked as unverified.

Parameters

options
objectRequired

An object containing properties for updating.

Returns

Promise<void>

Signature

1declare function update(options: {
2 value?: string;
3 type?: 'email';
4 usedForAuth?: boolean;
5 isPrimary?: boolean;
6}): Promise<void>;

Examples

1await contactChannel.update({
2 value: "new-email@example.com",
3 usedForAuth: true,
4});

contactChannel.delete()

Deletes the contact channel.

Parameters

None.

Returns

Promise<void>

Signature

1declare function delete(): Promise<void>;

Examples

1await contactChannel.delete();

ServerContactChannel

Like ContactChannel, but includes additional methods and properties that require the SECRET_SERVER_KEY.

Usually obtained by calling serverUser.[list|use]ContactChannels().

Table of Contents

1type ServerContactChannel =
2 // Inherits all properties from ContactChannel
3 & ContactChannel //$stack-link-to:#contactchannel
4 & {
5 update(options): Promise<void>; //$stack-link-to:#servercontactchannelupdateoptions
6 };

serverContactChannel.update(options)

Updates the contact channel.

This method is similar to the one on ContactChannel, but also allows setting the isVerified property.

Parameters

options
objectRequired

An object containing properties for updating.

Returns

Promise<void>

Signature

1declare function update(options: {
2 value?: string;
3 type?: 'email';
4 usedForAuth?: boolean;
5 isVerified?: boolean;
6 isPrimary?: boolean;
7}): Promise<void>;

Examples

1await serverContactChannel.update({
2 value: "new-email@example.com",
3 usedForAuth: true,
4 isVerified: true,
5});