From 9e01a8d3c3daf3257f29ad63b3836dfa89c6200b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 9 Feb 2024 19:10:01 +0300 Subject: vnext: authorize on backend --- vnext/src/api/index.js | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) (limited to 'vnext/src/api/index.js') 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} 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') } /** -- cgit v1.2.3