@kiwicom/smart-faq
Version:
49 lines (44 loc) • 1.2 kB
JavaScript
// @flow
import fetch from 'isomorphic-fetch';
export const endPoints = {
authApiUrl: 'https://auth.skypicker.com',
};
export const loginEndpoint = endPoints.authApiUrl + '/v1/user.login';
export const socialLoginEndpoint =
endPoints.authApiUrl + '/v1/oauth.getAuthorizationUrl';
const USER = process.env.KIWILOGIN_USER;
export const Requester = {
login: (
login: string,
password: string,
authorization?: string,
brand?: string,
) =>
fetch(loginEndpoint, {
method: 'post',
headers: {
Authorization:
'Basic ' + window.btoa(`${USER || authorization ?? ''}:`),
'Content-type': 'application/json',
},
body: JSON.stringify({
login,
password,
brand: brand ?? 'kiwicom',
}),
})
.then(r => r.json())
.then(r => (r.token ? r.token : Promise.reject(r))),
socialLogin: (payload: {}) =>
fetch(socialLoginEndpoint, {
method: 'post',
headers: {
'Content-type': 'application/json',
},
body: JSON.stringify(payload),
})
.then(r => r.json())
.then(r =>
r.authorization_url ? r.authorization_url : Promise.reject(r),
),
};