Skip to content

Commit

Permalink
changed registration and login in oauth condition (#266)
Browse files Browse the repository at this point in the history
## Изменения
Поменял местами запросы на регистрацию и логин через оаутх. Убрал лишние
логи в консоль.
  • Loading branch information
BatuevIO authored and fizfakovets committed Nov 13, 2024
1 parent cf49c28 commit f2ee6b8
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/components/IrdomAuthButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ onMounted(async () => {
});
async function clickHandler() {
console.log('кликнул', props.button.link, props.unlink);
if (props.unlink) {
await apiClient.DELETE(`/auth/${props.button.link}`);
console.log('deleted', props.button.link);
location.reload(); // TODO: придумать нормальное решение
} else if (authUrl.value) {
window.open(authUrl.value, '_self');
Expand Down
15 changes: 4 additions & 11 deletions src/router/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export const authHandler: NavigationGuard = async to => {

if (to.path.startsWith('/auth/oauth-authorized')) {
const methodLink = to.params.method;
console.log(methodLink, profileStore.isUserLogged);
if (!isAuthMethod(methodLink)) {
console.log('failed', methodLink);
return {
path: '/auth/error',
query: { text: 'Метод авторизации не существует', from: 'oauth' },
Expand All @@ -57,32 +55,29 @@ export const authHandler: NavigationGuard = async to => {
}

if (to.hash === '' && Object.keys(to.query).length === 0) {
console.log('Нет параметров входа', methodLink);
return {
path: '/auth/error',
query: { text: 'Отсутствуют параметры входа', from: 'oauth' },
replace: true,
};
}

const { data, response, error } = profileStore.isUserLogged
? await apiClient.POST(`/auth/${methodLink}/registration`, {
const { data, response } = profileStore.isUserLogged
? await apiClient.POST(`/auth/${methodLink}/login`, { body: { ...to.query } })
: await apiClient.POST(`/auth/${methodLink}/registration`, {
body: {
...to.query,
session_name: navigator.userAgent ?? UNKNOWN_DEVICE,
},
})
: await apiClient.POST(`/auth/${methodLink}/login`, { body: { ...to.query } });
});

if (response.ok && data?.token) {
console.log('Успешно вошел', methodLink);
LocalStorage.set(LocalStorageItem.Token, data.token);
profileStore.updateToken();
toastStore.push({ title: 'Вы успешно вошли в аккаунт' });
return { path: '/profile', replace: true };
} else {
if (response.status === 401) {
console.log('401 произошла', response, data, error);
const id_token = data?.token;

if (typeof id_token !== 'string') {
Expand All @@ -99,7 +94,6 @@ export const authHandler: NavigationGuard = async to => {
}

if (response.status === 422) {
console.log('422 произошла');
return {
path: '/auth/error',
query: { text: 'Выбран неверный аккаунт', from: 'oauth' },
Expand All @@ -108,7 +102,6 @@ export const authHandler: NavigationGuard = async to => {
}

if (response.status === 409) {
console.log('409 произошла');
return {
path: '/auth/error',
query: { text: 'Аккаунт с такими данными уже существуют', from: 'oauth' },
Expand Down
2 changes: 0 additions & 2 deletions src/views/profile/ProfileEditAuthView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ onMounted(async () => {
profileStore.updateToken(history.state.token);
delete history.state.token;
}
console.log(profileStore.authMethods);
AuthApi.getMe(['auth_methods']);
console.log(profileStore.authMethods);
});
const canLinked = computed(() =>
Expand Down
1 change: 0 additions & 1 deletion src/views/profile/ProfileView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const route = useRoute();
const toolbar = useToolbar();
const isOwnProfile = !('id' in route.params) || route.params.id === undefined;
console.log(isOwnProfile);
const buttons: ToolbarActionItem[] = [];
Expand Down

0 comments on commit f2ee6b8

Please sign in to comment.