From 88600c012c892c969f1e5df7ec5f46874513a058 Mon Sep 17 00:00:00 2001 From: simeng-li Date: Tue, 17 May 2022 10:18:09 +0800 Subject: [PATCH] fix(ui): add default success true for no response api (#842) * fix(ui): add default success true for no response api add default success true for no response api * fix(ui): code name code name * fix(ui): fix test fix test --- packages/ui/src/apis/index.test.ts | 18 +++++++++--------- packages/ui/src/apis/register.ts | 16 ++++++++++------ packages/ui/src/apis/sign-in.ts | 16 ++++++++++------ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/packages/ui/src/apis/index.test.ts b/packages/ui/src/apis/index.test.ts index 9944fe050..9f6955304 100644 --- a/packages/ui/src/apis/index.test.ts +++ b/packages/ui/src/apis/index.test.ts @@ -34,7 +34,7 @@ describe('api', () => { const username = 'username'; const password = 'password'; const phone = '18888888'; - const passcode = '111111'; + const code = '111111'; const email = 'foo@logto.io'; const mockKyPost = ky.post as jest.Mock; @@ -93,11 +93,11 @@ describe('api', () => { redirectTo: '/', }), }); - await verifySignInSmsPasscode(phone, passcode); + await verifySignInSmsPasscode(phone, code); expect(ky.post).toBeCalledWith('/api/session/sign-in/passwordless/sms/verify-passcode', { json: { phone, - passcode, + code, }, }); }); @@ -117,11 +117,11 @@ describe('api', () => { redirectTo: '/', }), }); - await verifySignInEmailPasscode(email, passcode); + await verifySignInEmailPasscode(email, code); expect(ky.post).toBeCalledWith('/api/session/sign-in/passwordless/email/verify-passcode', { json: { email, - passcode, + code, }, }); }); @@ -151,11 +151,11 @@ describe('api', () => { }); it('verifyRegisterSmsPasscode', async () => { - await verifyRegisterSmsPasscode(phone, passcode); + await verifyRegisterSmsPasscode(phone, code); expect(ky.post).toBeCalledWith('/api/session/register/passwordless/sms/verify-passcode', { json: { phone, - passcode, + code, }, }); }); @@ -170,11 +170,11 @@ describe('api', () => { }); it('verifyRegisterEmailPasscode', async () => { - await verifyRegisterEmailPasscode(email, passcode); + await verifyRegisterEmailPasscode(email, code); expect(ky.post).toBeCalledWith('/api/session/register/passwordless/email/verify-passcode', { json: { email, - passcode, + code, }, }); }); diff --git a/packages/ui/src/apis/register.ts b/packages/ui/src/apis/register.ts index 0e408b556..d2c4791e7 100644 --- a/packages/ui/src/apis/register.ts +++ b/packages/ui/src/apis/register.ts @@ -16,16 +16,18 @@ export const register = async (username: string, password: string) => { }; export const sendRegisterSmsPasscode = async (phone: string) => { - return api + await api .post('/api/session/register/passwordless/sms/send-passcode', { json: { phone, }, }) .json(); + + return { success: true }; }; -export const verifyRegisterSmsPasscode = async (phone: string, passcode: string) => { +export const verifyRegisterSmsPasscode = async (phone: string, code: string) => { type Response = { redirectTo: string; }; @@ -34,23 +36,25 @@ export const verifyRegisterSmsPasscode = async (phone: string, passcode: string) .post('/api/session/register/passwordless/sms/verify-passcode', { json: { phone, - passcode, + code, }, }) .json(); }; export const sendRegisterEmailPasscode = async (email: string) => { - return api + await api .post('/api/session/register/passwordless/email/send-passcode', { json: { email, }, }) .json(); + + return { success: true }; }; -export const verifyRegisterEmailPasscode = async (email: string, passcode: string) => { +export const verifyRegisterEmailPasscode = async (email: string, code: string) => { type Response = { redirectTo: string; }; @@ -59,7 +63,7 @@ export const verifyRegisterEmailPasscode = async (email: string, passcode: strin .post('/api/session/register/passwordless/email/verify-passcode', { json: { email, - passcode, + code, }, }) .json(); diff --git a/packages/ui/src/apis/sign-in.ts b/packages/ui/src/apis/sign-in.ts index 80c3f06f8..537598c59 100644 --- a/packages/ui/src/apis/sign-in.ts +++ b/packages/ui/src/apis/sign-in.ts @@ -23,18 +23,20 @@ export const signInBasic = async (username: string, password: string, socialToBi }; export const sendSignInSmsPasscode = async (phone: string) => { - return api + await api .post('/api/session/sign-in/passwordless/sms/send-passcode', { json: { phone, }, }) .json(); + + return { success: true }; }; export const verifySignInSmsPasscode = async ( phone: string, - passcode: string, + code: string, socialToBind?: string ) => { type Response = { @@ -45,7 +47,7 @@ export const verifySignInSmsPasscode = async ( .post('/api/session/sign-in/passwordless/sms/verify-passcode', { json: { phone, - passcode, + code, }, }) .json(); @@ -58,18 +60,20 @@ export const verifySignInSmsPasscode = async ( }; export const sendSignInEmailPasscode = async (email: string) => { - return api + await api .post('/api/session/sign-in/passwordless/email/send-passcode', { json: { email, }, }) .json(); + + return { success: true }; }; export const verifySignInEmailPasscode = async ( email: string, - passcode: string, + code: string, socialToBind?: string ) => { type Response = { @@ -80,7 +84,7 @@ export const verifySignInEmailPasscode = async ( .post('/api/session/sign-in/passwordless/email/verify-passcode', { json: { email, - passcode, + code, }, }) .json();