From c6a09c27c1dd0d9c404143c8f35efb60ca8782da Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Thu, 1 Sep 2022 14:48:19 +0700 Subject: [PATCH] fixed auth urls for new endpoints --- src/api/auth/index.ts | 44 ++++++++++++++++++++++++++++++++----------- src/constants/api.ts | 16 ++++++++-------- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/api/auth/index.ts b/src/api/auth/index.ts index 175bb08f..0d589d02 100644 --- a/src/api/auth/index.ts +++ b/src/api/auth/index.ts @@ -28,14 +28,24 @@ export const apiUserLogin = ({ username, password }: ApiUserLoginRequest) => .post(API.USER.LOGIN, { username, password }) .then(cleanResult); -export const apiAuthGetUser = () => api.get(API.USER.ME).then(cleanResult); +export const apiAuthGetUser = () => + api.get(API.USER.ME).then(cleanResult); -export const apiAuthGetUserProfile = ({ username }: ApiAuthGetUserProfileRequest) => - api.get(API.USER.PROFILE(username)).then(cleanResult); - -export const apiAuthGetUpdates = ({ exclude_dialogs, last }: ApiAuthGetUpdatesRequest) => +export const apiAuthGetUserProfile = ({ + username, +}: ApiAuthGetUserProfileRequest) => api - .get(API.USER.GET_UPDATES, { params: { exclude_dialogs, last } }) + .get(API.USER.PROFILE(username)) + .then(cleanResult); + +export const apiAuthGetUpdates = ({ + exclude_dialogs, + last, +}: ApiAuthGetUpdatesRequest) => + api + .get(API.USER.GET_UPDATES, { + params: { exclude_dialogs, last }, + }) .then(cleanResult); export const apiUpdateUser = ({ user }: ApiUpdateUserRequest) => @@ -47,25 +57,37 @@ export const apiRequestRestoreCode = (field: string) => .then(cleanResult); export const apiCheckRestoreCode = ({ code }: ApiCheckRestoreCodeRequest) => - api.get(API.USER.REQUEST_CODE(code)).then(cleanResult); + api + .get(API.USER.REQUEST_CODE(code)) + .then(cleanResult); export const apiRestoreCode = ({ code, password }: ApiRestoreCodeRequest) => api - .post(API.USER.REQUEST_CODE(code), { password }) + .put(API.USER.REQUEST_CODE(code), { password }) .then(cleanResult); export const apiGetSocials = () => api.get(API.USER.GET_SOCIALS).then(cleanResult); export const apiDropSocial = ({ id, provider }: ApiDropSocialRequest) => - api.delete(API.USER.DROP_SOCIAL(provider, id)).then(cleanResult); + api + .delete(API.USER.DROP_SOCIAL(provider, id)) + .then(cleanResult); export const apiAttachSocial = ({ token }: ApiAttachSocialRequest) => api .post(API.USER.ATTACH_SOCIAL, { token }) .then(cleanResult); -export const apiLoginWithSocial = ({ token, username, password }: ApiLoginWithSocialRequest) => +export const apiLoginWithSocial = ({ + token, + username, + password, +}: ApiLoginWithSocialRequest) => api - .post(API.USER.LOGIN_WITH_SOCIAL, { token, username, password }) + .post(API.USER.LOGIN_WITH_SOCIAL, { + token, + username, + password, + }) .then(cleanResult); diff --git a/src/constants/api.ts b/src/constants/api.ts index 19afa091..234c6635 100644 --- a/src/constants/api.ts +++ b/src/constants/api.ts @@ -5,17 +5,17 @@ import { CONFIG } from '~/utils/config'; export const API = { BASE: CONFIG.apiHost, USER: { - LOGIN: '/users/login', + LOGIN: '/auth', OAUTH_WINDOW: (provider: OAuthProvider) => `${CONFIG.apiHost}oauth/${provider}/redirect`, - ME: '/users/', - PROFILE: (username: string) => `/users/user/${username}/profile`, - MESSAGES: (username: string) => `/users/user/${username}/messages`, - MESSAGE_SEND: (username: string) => `/users/user/${username}/messages`, + ME: '/auth', + PROFILE: (username: string) => `/users/${username}/profile`, + MESSAGES: (username: string) => `/users/${username}/messages`, + MESSAGE_SEND: (username: string) => `/users/${username}/messages`, MESSAGE_DELETE: (username: string, id: number) => - `/users/user/${username}/messages/${id}`, - GET_UPDATES: '/users/updates', - REQUEST_CODE: (code?: string) => `/users/restore/${code || ''}`, + `/users/${username}/messages/${id}`, + GET_UPDATES: '/auth/updates', + REQUEST_CODE: (code?: string) => `/auth/restore/${code || ''}`, UPLOAD: (target, type) => `/upload/${target}/${type}`, GET_SOCIALS: '/oauth/',