auth api fix and yandex redirect

This commit is contained in:
Максим Демидов 2024-02-16 18:59:16 +10:00
parent 9fec063a44
commit 5bda27a6bc
3 changed files with 14 additions and 10 deletions

View File

@ -14,7 +14,7 @@ export const login = (
data: AuthAPI.POST.Login.Params, data: AuthAPI.POST.Login.Params,
): Promise<AuthAPI.POST.Login.Response> => baseApi.post('login', data) ): Promise<AuthAPI.POST.Login.Response> => baseApi.post('login', data)
export const loginYandex = (): Promise<YandexAPI.GET.loginYandex.Response> => baseURL.get('/login/yandex/') export const loginYandex = (): Promise<YandexAPI.GET.loginYandex.Response> => baseURL.get('/login/yandex')
export const YandexCallBack = (token : String): Promise<YandexAPI.GET.YandexCallBack.Response> => baseURL.get(`/login/yandex/callback?access_token=${token}`) export const YandexCallBack = (token : String): Promise<YandexAPI.GET.YandexCallBack.Response> => baseURL.get(`/login/yandex/callback?access_token=${token}`)
@ -57,10 +57,12 @@ export namespace YandexAPI {
export namespace YandexCallBack { export namespace YandexCallBack {
export type Params = { token: string } export type Params = { token: string }
export type Response = AxiosResponse<{ export type Response = AxiosResponse<{
access_token: string, data : {
success: boolean, access_token: string,
token_type: string, success: boolean,
message: string | null token_type: string,
message: string | null
}
}> }>
} }
} }

View File

@ -46,13 +46,15 @@ export const useAuthStore = defineStore(Stores.AUTH, () => {
const onYandex = async () => { const onYandex = async () => {
try { try {
loading.value = true loading.value = true;
const res = await loginYandex() const res = await loginYandex();
await router.push({ name: Routes.INDEX }) const redirect_url = res.data
console.log(res.data);
window.location.href = res.data;
} catch (e: any) { } catch (e: any) {
console.log(e.response.data.message) console.log(e.response.data.message)
} finally { } finally {
loading.value = false loading.value = false;
} }
} }

View File

@ -14,6 +14,6 @@ export const callBack = async () => {
const data = await YandexCallBack(token); const data = await YandexCallBack(token);
setJWT(data.data.data.access_token); setJWT(data.data.data.access_token);
console.log(data.data.data.access_token)
router.push({ name : Routes.INDEX }); router.push({ name : Routes.INDEX });
}; };