Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed registration and login in oauth condition #266

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading