yandex oauth
This commit is contained in:
parent
edbf304790
commit
9fec063a44
1843
package-lock.json
generated
1843
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -121,4 +121,12 @@ export const routes: RouteRecordRaw[] = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/login/yandex/processing',
|
||||||
|
name: Routes.YANDEX_PROCESSING,
|
||||||
|
component: () => import('@/pages/callback/ui/CallBack/AuthCallBack.vue'),
|
||||||
|
meta: {
|
||||||
|
middleware: [guest]
|
||||||
|
},
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import type { AxiosResponse } from 'axios'
|
import type { AxiosResponse } from 'axios'
|
||||||
import { fetchUser } from '@/entities'
|
import { fetchUser } from '@/entities'
|
||||||
import { type AuthData, baseApi } from '@/shared'
|
import { type AuthData, baseApi, baseURL } from '@/shared'
|
||||||
import type { RegistrationData } from '../model'
|
import type { RegistrationData } from '../model'
|
||||||
|
|
||||||
export const tokenValidate = async () => {
|
export const tokenValidate = async () => {
|
||||||
@ -14,6 +14,10 @@ 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 YandexCallBack = (token : String): Promise<YandexAPI.GET.YandexCallBack.Response> => baseURL.get(`/login/yandex/callback?access_token=${token}`)
|
||||||
|
|
||||||
export const registration = (
|
export const registration = (
|
||||||
data: AuthAPI.POST.Registration.Params,
|
data: AuthAPI.POST.Registration.Params,
|
||||||
): Promise<AuthAPI.POST.Registration.Response> => baseApi.post('register', data)
|
): Promise<AuthAPI.POST.Registration.Response> => baseApi.post('register', data)
|
||||||
@ -46,3 +50,24 @@ export namespace AuthAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export namespace YandexAPI {
|
||||||
|
|
||||||
|
export namespace GET {
|
||||||
|
export namespace YandexCallBack {
|
||||||
|
export type Params = { token: string }
|
||||||
|
export type Response = AxiosResponse<{
|
||||||
|
access_token: string,
|
||||||
|
success: boolean,
|
||||||
|
token_type: string,
|
||||||
|
message: string | null
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace GET {
|
||||||
|
export namespace loginYandex {
|
||||||
|
export type Response = AxiosResponse<string>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { ref } from 'vue'
|
|||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { toast } from 'vue3-toastify'
|
import { toast } from 'vue3-toastify'
|
||||||
import { type AuthData, Routes, Stores, useJWT } from '@/shared'
|
import { type AuthData, Routes, Stores, useJWT } from '@/shared'
|
||||||
import { login, logout, registration } from '../../api'
|
import { login, loginYandex, logout, registration } from '../../api'
|
||||||
|
|
||||||
enum MedicType {
|
enum MedicType {
|
||||||
DOCTOR = 'doctor',
|
DOCTOR = 'doctor',
|
||||||
@ -44,6 +44,18 @@ export const useAuthStore = defineStore(Stores.AUTH, () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onYandex = async () => {
|
||||||
|
try {
|
||||||
|
loading.value = true
|
||||||
|
const res = await loginYandex()
|
||||||
|
await router.push({ name: Routes.INDEX })
|
||||||
|
} catch (e: any) {
|
||||||
|
console.log(e.response.data.message)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onRegistration = async (data: NonNullable<RegistrationData>) => {
|
const onRegistration = async (data: NonNullable<RegistrationData>) => {
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
@ -78,6 +90,7 @@ export const useAuthStore = defineStore(Stores.AUTH, () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
onLogin,
|
onLogin,
|
||||||
|
onYandex,
|
||||||
onRegistration,
|
onRegistration,
|
||||||
onLogout,
|
onLogout,
|
||||||
loading,
|
loading,
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
:loading="auth.loading"
|
:loading="auth.loading"
|
||||||
title="Вход"
|
title="Вход"
|
||||||
@submit="login"
|
@submit="login"
|
||||||
|
@login-yandex="loginYandex"
|
||||||
@set-registration="setRegistration"
|
@set-registration="setRegistration"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -20,6 +21,9 @@ const emit = defineEmits(['setRegistration'])
|
|||||||
const login = async (data: AuthData) => {
|
const login = async (data: AuthData) => {
|
||||||
await auth.onLogin(data)
|
await auth.onLogin(data)
|
||||||
}
|
}
|
||||||
|
const loginYandex = async () => {
|
||||||
|
await auth.onYandex()
|
||||||
|
}
|
||||||
const setRegistration = (value: boolean) => {
|
const setRegistration = (value: boolean) => {
|
||||||
emit('setRegistration', value)
|
emit('setRegistration', value)
|
||||||
}
|
}
|
||||||
|
1
src/features/callback/index.ts
Normal file
1
src/features/callback/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './model'
|
19
src/features/callback/model/index.ts
Normal file
19
src/features/callback/model/index.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { type AuthData, Routes, Stores, useJWT } from '@/shared';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
import { YandexCallBack } from '@/features';
|
||||||
|
import { QueryParamsValidator } from '@/shared';
|
||||||
|
|
||||||
|
|
||||||
|
export const callBack = async () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const { setJWT } = useJWT();
|
||||||
|
|
||||||
|
const url = QueryParamsValidator();
|
||||||
|
const params = new URL(url).searchParams;
|
||||||
|
const token = params.get('access_token') as string;
|
||||||
|
|
||||||
|
const data = await YandexCallBack(token);
|
||||||
|
setJWT(data.data.data.access_token);
|
||||||
|
|
||||||
|
router.push({ name : Routes.INDEX });
|
||||||
|
};
|
@ -1,3 +1,4 @@
|
|||||||
export * from './auth'
|
export * from './auth'
|
||||||
export * from './patient'
|
export * from './patient'
|
||||||
export * from './medical'
|
export * from './medical'
|
||||||
|
export * from './callback'
|
1
src/pages/callback/index.ts
Normal file
1
src/pages/callback/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './ui'
|
8
src/pages/callback/ui/CallBack/AuthCallBack.vue
Normal file
8
src/pages/callback/ui/CallBack/AuthCallBack.vue
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<template>
|
||||||
|
<div>void</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { callBack } from '@/features';
|
||||||
|
callBack();
|
||||||
|
</script>
|
3
src/pages/callback/ui/CallBack/index.ts
Normal file
3
src/pages/callback/ui/CallBack/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import AuthCallBack from './AuthCallBack.vue'
|
||||||
|
|
||||||
|
export { AuthCallBack }
|
1
src/pages/callback/ui/index.ts
Normal file
1
src/pages/callback/ui/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './CallBack'
|
@ -10,6 +10,10 @@ const baseApi = axios.create({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const baseURL = axios.create({
|
||||||
|
baseURL: config.mainHost
|
||||||
|
})
|
||||||
|
|
||||||
const medicalApi = axios.create({
|
const medicalApi = axios.create({
|
||||||
baseURL: config.medicalURL,
|
baseURL: config.medicalURL,
|
||||||
headers: {
|
headers: {
|
||||||
@ -17,4 +21,4 @@ const medicalApi = axios.create({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export { baseApi, medicalApi }
|
export { baseApi, medicalApi, baseURL }
|
||||||
|
5
src/shared/lib/hooks/QueryParamsValidator.ts
Normal file
5
src/shared/lib/hooks/QueryParamsValidator.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export const QueryParamsValidator = () => {
|
||||||
|
let url = window.location.href;
|
||||||
|
url = url.replace('#', '?');
|
||||||
|
return url
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
export * from './usePageTitle'
|
export * from './usePageTitle'
|
||||||
export * from './useJWT'
|
export * from './useJWT'
|
||||||
|
export * from './QueryParamsValidator'
|
@ -15,7 +15,7 @@
|
|||||||
/>
|
/>
|
||||||
<span :class="bem('divider')">Или</span>
|
<span :class="bem('divider')">Или</span>
|
||||||
<div :class="bem('socials')">
|
<div :class="bem('socials')">
|
||||||
<button-social-component type="yandex" />
|
<button-social-component type="yandex" @click="onYandex" />
|
||||||
<button-social-component type="google" />
|
<button-social-component type="google" />
|
||||||
<button-social-component type="vk" />
|
<button-social-component type="vk" />
|
||||||
</div>
|
</div>
|
||||||
@ -44,7 +44,7 @@ export type AuthFormProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<AuthFormProps>()
|
const props = defineProps<AuthFormProps>()
|
||||||
const emit = defineEmits(['submit', 'setRegistration'])
|
const emit = defineEmits(['submit', 'loginYandex', 'setRegistration'])
|
||||||
|
|
||||||
const data = ref<AuthData>({
|
const data = ref<AuthData>({
|
||||||
email: '',
|
email: '',
|
||||||
@ -70,6 +70,11 @@ const onClick = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onYandex = () => {
|
||||||
|
emit('loginYandex')
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const onChangeType = () => {
|
const onChangeType = () => {
|
||||||
emit('setRegistration', !props.isRegistration)
|
emit('setRegistration', !props.isRegistration)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user