From 5bda27a6bc909c804922d7988ab6235b6e1d45a2 Mon Sep 17 00:00:00 2001 From: Tech7ie Date: Fri, 16 Feb 2024 18:59:16 +1000 Subject: [PATCH] auth api fix and yandex redirect --- src/features/auth/api/index.ts | 12 +++++++----- src/features/auth/model/module/index.ts | 10 ++++++---- src/features/callback/model/index.ts | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/features/auth/api/index.ts b/src/features/auth/api/index.ts index 33e6edd..636e559 100644 --- a/src/features/auth/api/index.ts +++ b/src/features/auth/api/index.ts @@ -14,7 +14,7 @@ export const login = ( data: AuthAPI.POST.Login.Params, ): Promise => baseApi.post('login', data) -export const loginYandex = (): Promise => baseURL.get('/login/yandex/') +export const loginYandex = (): Promise => baseURL.get('/login/yandex') export const YandexCallBack = (token : String): Promise => baseURL.get(`/login/yandex/callback?access_token=${token}`) @@ -57,10 +57,12 @@ export namespace YandexAPI { export namespace YandexCallBack { export type Params = { token: string } export type Response = AxiosResponse<{ - access_token: string, - success: boolean, - token_type: string, - message: string | null + data : { + access_token: string, + success: boolean, + token_type: string, + message: string | null + } }> } } diff --git a/src/features/auth/model/module/index.ts b/src/features/auth/model/module/index.ts index 080c21b..b8f3254 100644 --- a/src/features/auth/model/module/index.ts +++ b/src/features/auth/model/module/index.ts @@ -46,13 +46,15 @@ export const useAuthStore = defineStore(Stores.AUTH, () => { const onYandex = async () => { try { - loading.value = true - const res = await loginYandex() - await router.push({ name: Routes.INDEX }) + loading.value = true; + const res = await loginYandex(); + const redirect_url = res.data + console.log(res.data); + window.location.href = res.data; } catch (e: any) { console.log(e.response.data.message) } finally { - loading.value = false + loading.value = false; } } diff --git a/src/features/callback/model/index.ts b/src/features/callback/model/index.ts index ee2b732..032e0f7 100644 --- a/src/features/callback/model/index.ts +++ b/src/features/callback/model/index.ts @@ -14,6 +14,6 @@ export const callBack = async () => { const data = await YandexCallBack(token); setJWT(data.data.data.access_token); - + console.log(data.data.data.access_token) router.push({ name : Routes.INDEX }); }; \ No newline at end of file