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

Adds template name to loginWithOTP and loginWithMagicLink #643

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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, overrides } = configuration;

const requestPayload = createJsonRpcRequestPayload(
this.sdk.testMode ? MagicPayloadMethod.LoginWithMagicLinkTestMode : MagicPayloadMethod.LoginWithMagicLink,
[{ email, showUI, redirectURI }],
[{ email, showUI, redirectURI, overrides }],
);
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, overrides } = configuration;
const requestPayload = createJsonRpcRequestPayload(
this.sdk.testMode ? MagicPayloadMethod.LoginWithEmailOTPTestMode : MagicPayloadMethod.LoginWithEmailOTP,
[{ email, showUI, deviceCheckUI }],
[{ email, showUI, deviceCheckUI, overrides }],
);
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 `overrides` parameter', async () => {
const magic = createMagicSDK();
magic.auth.request = jest.fn();

await magic.auth.loginWithEmailOTP({ email: expectedEmail, overrides: { variation: '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, overrides: { variation: '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,20 @@ 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 `overrides` parameter', async () => {
const magic = createMagicSDK();
magic.auth.request = jest.fn();

await magic.auth.loginWithMagicLink({ email: 'test', showUI: true, overrides: { variation: '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, overrides: { variation: '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
18 changes: 18 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,15 @@ 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 variation is passed here.
*/
overrides?: {
variation?: string;
};
}

export interface LoginWithSmsConfiguration {
Expand Down Expand Up @@ -54,6 +63,15 @@ 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 variation is passed here.
*/
overrides?: {
variation?: string;
};
}

/**
Expand Down