0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-31 22:51:25 -05:00

feat(ui): add social apis (#518)

add social apis
This commit is contained in:
simeng-li 2022-04-09 12:20:21 +08:00 committed by GitHub
parent fb65c65893
commit aa9cc806bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 121 additions and 16 deletions

View file

@ -15,6 +15,7 @@ import {
verifyEmailPasscode,
verifyPhonePasscode,
} from './sign-in';
import { signInWithSocial, signInToSoical, bindSocialAccount, registerWithSocial } from './social';
jest.mock('ky', () => ({
post: jest.fn(() => ({
@ -47,7 +48,7 @@ describe('api', () => {
it('sendPhonePasscode', async () => {
await sendPhonePasscode(phone);
expect(ky.post).toBeCalledWith('/session/sign-in/passwordless/phone/send-passcode', {
expect(ky.post).toBeCalledWith('/api/session/sign-in/passwordless/phone/send-passcode', {
json: {
phone,
},
@ -56,7 +57,7 @@ describe('api', () => {
it('verifyPhonePasscode', async () => {
await verifyPhonePasscode(phone, passcode);
expect(ky.post).toBeCalledWith('/session/sign-in/passwordless/phone/verify-passcode', {
expect(ky.post).toBeCalledWith('/api/session/sign-in/passwordless/phone/verify-passcode', {
json: {
phone,
passcode,
@ -66,7 +67,7 @@ describe('api', () => {
it('sendEmailPasscode', async () => {
await sendEmailPasscode(email);
expect(ky.post).toBeCalledWith('/session/sign-in/passwordless/email/send-passcode', {
expect(ky.post).toBeCalledWith('/api/session/sign-in/passwordless/email/send-passcode', {
json: {
email,
},
@ -75,7 +76,7 @@ describe('api', () => {
it('verifyEmailPasscode', async () => {
await verifyEmailPasscode(email, passcode);
expect(ky.post).toBeCalledWith('/session/sign-in/passwordless/email/verify-passcode', {
expect(ky.post).toBeCalledWith('/api/session/sign-in/passwordless/email/verify-passcode', {
json: {
email,
passcode,
@ -100,7 +101,7 @@ describe('api', () => {
it('registerSendPhonePasscode', async () => {
await registerSendPhonePasscode(phone);
expect(ky.post).toBeCalledWith('/session/register/passwordless/phone/send-passcode', {
expect(ky.post).toBeCalledWith('/api/session/register/passwordless/phone/send-passcode', {
json: {
phone,
},
@ -109,7 +110,7 @@ describe('api', () => {
it('registerVerifyPhonePasscode', async () => {
await registerVerifyPhonePasscode(phone, passcode);
expect(ky.post).toBeCalledWith('/session/register/passwordless/phone/verify-passcode', {
expect(ky.post).toBeCalledWith('/api/session/register/passwordless/phone/verify-passcode', {
json: {
phone,
passcode,
@ -119,7 +120,7 @@ describe('api', () => {
it('registerSendEmailPasscode', async () => {
await registerSendEmailPasscode(email);
expect(ky.post).toBeCalledWith('/session/register/passwordless/email/send-passcode', {
expect(ky.post).toBeCalledWith('/api/session/register/passwordless/email/send-passcode', {
json: {
email,
},
@ -128,11 +129,53 @@ describe('api', () => {
it('registerVerifyEmailPasscode', async () => {
await registerVerifyEmailPasscode(email, passcode);
expect(ky.post).toBeCalledWith('/session/register/passwordless/email/verify-passcode', {
expect(ky.post).toBeCalledWith('/api/session/register/passwordless/email/verify-passcode', {
json: {
email,
passcode,
},
});
});
it('signInWithSocial', async () => {
await signInWithSocial('connectorId', 'state', 'redirectUri');
expect(ky.post).toBeCalledWith('/api/session/sign-in/social', {
json: {
connectorId: 'connectorId',
state: 'state',
redirectUri: 'redirectUri',
},
});
});
it('signInToSoical', async () => {
const parameters = {
connectorId: 'connectorId',
state: 'state',
redirectUri: 'redirectUri',
code: 'code',
};
await signInToSoical(parameters);
expect(ky.post).toBeCalledWith('/api/session/sign-in/social', {
json: parameters,
});
});
it('bindSocialAccount', async () => {
await bindSocialAccount('connectorId');
expect(ky.post).toBeCalledWith('/api/session/sign-in/bind-social-related-user', {
json: {
connectorId: 'connectorId',
},
});
});
it('registerWithSocial', async () => {
await registerWithSocial('connectorId');
expect(ky.post).toBeCalledWith('/api/session/register/social', {
json: {
connectorId: 'connectorId',
},
});
});
});

View file

@ -17,7 +17,7 @@ export const register = async (username: string, password: string) => {
export const sendPhonePasscode = async (phone: string) => {
return ky
.post('/session/register/passwordless/phone/send-passcode', {
.post('/api/session/register/passwordless/phone/send-passcode', {
json: {
phone,
},
@ -31,7 +31,7 @@ export const verifyPhonePasscode = async (phone: string, passcode: string) => {
};
return ky
.post('/session/register/passwordless/phone/verify-passcode', {
.post('/api/session/register/passwordless/phone/verify-passcode', {
json: {
phone,
passcode,
@ -42,7 +42,7 @@ export const verifyPhonePasscode = async (phone: string, passcode: string) => {
export const sendEmailPasscode = async (email: string) => {
return ky
.post('/session/register/passwordless/email/send-passcode', {
.post('/api/session/register/passwordless/email/send-passcode', {
json: {
email,
},
@ -56,7 +56,7 @@ export const verifyEmailPasscode = async (email: string, passcode: string) => {
};
return ky
.post('/session/register/passwordless/email/verify-passcode', {
.post('/api/session/register/passwordless/email/verify-passcode', {
json: {
email,
passcode,

View file

@ -17,7 +17,7 @@ export const signInBasic = async (username: string, password: string) => {
export const sendPhonePasscode = async (phone: string) => {
return ky
.post('/session/sign-in/passwordless/phone/send-passcode', {
.post('/api/session/sign-in/passwordless/phone/send-passcode', {
json: {
phone,
},
@ -31,7 +31,7 @@ export const verifyPhonePasscode = async (phone: string, passcode: string) => {
};
return ky
.post('/session/sign-in/passwordless/phone/verify-passcode', {
.post('/api/session/sign-in/passwordless/phone/verify-passcode', {
json: {
phone,
passcode,
@ -42,7 +42,7 @@ export const verifyPhonePasscode = async (phone: string, passcode: string) => {
export const sendEmailPasscode = async (email: string) => {
return ky
.post('/session/sign-in/passwordless/email/send-passcode', {
.post('/api/session/sign-in/passwordless/email/send-passcode', {
json: {
email,
},
@ -56,7 +56,7 @@ export const verifyEmailPasscode = async (email: string, passcode: string) => {
};
return ky
.post('/session/sign-in/passwordless/email/verify-passcode', {
.post('/api/session/sign-in/passwordless/email/verify-passcode', {
json: {
email,
passcode,

View file

@ -0,0 +1,62 @@
import ky from 'ky';
export const signInWithSocial = async (connectorId: string, state: string, redirectUri: string) => {
type Response = {
redirectTo: string;
};
return ky
.post('/api/session/sign-in/social', {
json: {
connectorId,
state,
redirectUri,
},
})
.json<Response>();
};
export const signInToSoical = async (parameters: {
connectorId: string;
state: string;
redirectUri: string;
code: string;
}) => {
type Response = {
redirectTo: string;
};
return ky
.post('/api/session/sign-in/social', {
json: parameters,
})
.json<Response>();
};
export const bindSocialAccount = async (connectorId: string) => {
type Response = {
redirectTo: string;
};
return ky
.post('/api/session/sign-in/bind-social-related-user', {
json: {
connectorId,
},
})
.json<Response>();
};
export const registerWithSocial = async (connectorId: string) => {
type Response = {
redirectTo: string;
};
return ky
.post('/api/session/register/social', {
json: {
connectorId,
},
})
.json<Response>();
};