diff options
author | 2024-02-09 19:10:01 +0300 | |
---|---|---|
committer | 2024-02-09 19:13:28 +0300 | |
commit | 9e01a8d3c3daf3257f29ad63b3836dfa89c6200b (patch) | |
tree | fc785536ffd05a2232da5222f55e9a5268f99f32 /vnext/src/api/index.js | |
parent | e2674c3b27174e408264b84f50bf86a13e2d3824 (diff) |
vnext: authorize on backend
Diffstat (limited to 'vnext/src/api/index.js')
-rw-r--r-- | vnext/src/api/index.js | 34 |
1 files changed, 4 insertions, 30 deletions
diff --git a/vnext/src/api/index.js b/vnext/src/api/index.js index 24f2fe88..4d2a81fa 100644 --- a/vnext/src/api/index.js +++ b/vnext/src/api/index.js @@ -1,5 +1,4 @@ import axios from 'axios' -import Cookies from 'universal-cookie' const apiBaseUrl = 'https://juick.com' @@ -72,41 +71,16 @@ const apiBaseUrl = 'https://juick.com' const client = axios.create({ - baseURL: apiBaseUrl -}) -client.interceptors.request.use(config => { - if (config.url.startsWith('/')) { - // only local URLs - let cookies = new Cookies() - config.params = Object.assign(config.params || {}, { - hash: cookies.get('hash') - }) - } - return config + baseURL: apiBaseUrl, + withCredentials: true }) /** * fetch my info - * @param {string=} username - * @param {string=} password * @returns {Promise<SecureUser, Error>} me object */ -export function me(username, password) { - let cookies = new Cookies() - return new Promise((resolve, reject) => { - client.get('/api/me', { - headers: username ? { - 'Authorization': 'Basic ' + window.btoa(unescape(encodeURIComponent(username + ':' + password))) - } : {} - }).then(response => { - let visitor = response.data - cookies.set('hash', visitor.hash, { path: '/' }) - resolve(visitor) - }).catch(reason => { - cookies.remove('hash', { path: '/' }) - reject(reason) - }) - }) +export function me() { + return client.get('/api/me') } /** |