Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email customization sdk updates #647

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add optional field to login methods
  • Loading branch information
chrisdakin-magic committed Oct 17, 2023
commit 8632019e6563c831a5ef7e363e1fb8ad1bde4041
8 changes: 4 additions & 4 deletions packages/@magic-sdk/provider/src/modules/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export class AuthModule extends BaseModule {
}).log();
}

const { email, showUI = true, redirectURI } = configuration;
const { email, showUI = true, redirectURI, customTemplateName } = configuration;

const requestPayload = createJsonRpcRequestPayload(
this.sdk.testMode ? MagicPayloadMethod.LoginWithMagicLinkTestMode : MagicPayloadMethod.LoginWithMagicLink,
[{ email, showUI, redirectURI }],
[{ email, showUI, redirectURI, customTemplateName }],
);
return this.request<string | null, LoginWithMagicLinkEventHandlers>(requestPayload);
}
Expand All @@ -78,10 +78,10 @@ export class AuthModule extends BaseModule {
* of 15 minutes)
*/
public loginWithEmailOTP(configuration: LoginWithEmailOTPConfiguration) {
const { email, showUI, deviceCheckUI } = configuration;
const { email, showUI, deviceCheckUI, customTemplateName } = configuration;
const requestPayload = createJsonRpcRequestPayload(
this.sdk.testMode ? MagicPayloadMethod.LoginWithEmailOTPTestMode : MagicPayloadMethod.LoginWithEmailOTP,
[{ email, showUI, deviceCheckUI }],
[{ email, showUI, deviceCheckUI, customTemplateName }],
);
const handle = this.request<string | null, LoginWithEmailOTPEventHandlers>(requestPayload);
if (!deviceCheckUI && handle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ test('Generates JSON RPC request payload with `showUI: false` parameter', async
expect(requestPayload.params).toEqual([{ email: expectedEmail, showUI: false }]);
});

test('Generates JSON RPC request payload with `customTemplateName` parameter', async () => {
const magic = createMagicSDK();
magic.auth.request = jest.fn();

await magic.auth.loginWithEmailOTP({ email: expectedEmail, customTemplateName: 'my custom template' });

const requestPayload = magic.auth.request.mock.calls[0][0];
expect(requestPayload.jsonrpc).toBe('2.0');
expect(requestPayload.method).toBe(MagicPayloadMethod.LoginWithEmailOTP);
expect(requestPayload.params).toEqual([{ email: expectedEmail, customTemplateName: 'my custom template' }]);
});

test('If `testMode` is enabled, testing-specific RPC method is used', async () => {
const magic = createMagicSDKTestMode();
magic.auth.request = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ test('Generates JSON RPC request payload with `redirectURI` parameter', async ()
expect(requestPayload.params).toEqual([{ email: 'test', showUI: true, redirectURI: 'helloworld' }]);
});

test('Generates JSON RPC request payload with `customTemplateName` parameter', async () => {
const magic = createMagicSDK();
magic.auth.request = jest.fn();

await magic.auth.loginWithMagicLink({ email: 'test', showUI: true, customTemplateName: 'my custom template' });

const requestPayload = magic.auth.request.mock.calls[0][0];
expect(requestPayload.jsonrpc).toBe('2.0');
expect(requestPayload.method).toBe(MagicPayloadMethod.LoginWithMagicLink);
expect(requestPayload.params).toEqual([{ email: 'test', showUI: true, customTemplateName: 'my custom template' }]);
});

test('If `testMode` is enabled, testing-specific RPC method is used', async () => {
const magic = createMagicSDKTestMode();
magic.auth.request = jest.fn();
Expand Down
14 changes: 14 additions & 0 deletions packages/@magic-sdk/types/src/modules/auth-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export interface LoginWithMagicLinkConfiguration {
* configure here.
*/
redirectURI?: string;

/**
* Enterprise users with a custom SMTP can create custom email templates
* from their dashboard. The default Magic loginWithMagicLink email will be
* overriden when a customTemplateName is passed here.
*/
customTemplateName?: string;
}

export interface LoginWithSmsConfiguration {
Expand Down Expand Up @@ -54,6 +61,13 @@ export interface LoginWithEmailOTPConfiguration {
* handle device check events, providing a more tailored user experience.
*/
deviceCheckUI?: boolean;

/**
* Enterprise users with a custom SMTP can create custom email templates
* from their dashboard. The default Magic loginWithOTP email will be
* overriden when a customTemplateName is passed here.
*/
customTemplateName?: string;
}

/**
Expand Down