Skip to content

Commit

Permalink
Fixed id_token being taken from the wrong place (#280)
Browse files Browse the repository at this point in the history
## Изменения
- Вместо code из URL теперь id_token забирается из ошибки, как и должно
быть.
- Теперь в /registration для нового аккаунта передается корректный
id_token

---------

Co-authored-by: Artem <[email protected]>
Co-authored-by: Artem Netsvetaev <[email protected]>
  • Loading branch information
3 people authored Nov 16, 2024
1 parent 102ad34 commit 621fdd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ export enum SessionInfo {
Expires = 'expires',
}

export interface LoginError {
status: string;
message: string;
ru: string;
id_token: string;
}

// achievement models
export type Reciever = achievementComponents['schemas']['RecieverGet'];
export interface AchievementGet {
Expand Down
9 changes: 5 additions & 4 deletions src/router/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NavigationGuard, RouteRecordRaw } from 'vue-router';
import { useProfileStore } from '@/store/profile';
import { useToastStore } from '@/store/toast';
import { AuthApi } from '@/api';
import { UNKNOWN_DEVICE } from '@/models';
import { UNKNOWN_DEVICE, LoginError } from '@/models';

import apiClient from '@/api/';
import { isAuthMethod } from '@/utils/authMethodName';
Expand Down Expand Up @@ -62,7 +62,7 @@ export const authHandler: NavigationGuard = async to => {
};
}

const { data, response } = profileStore.isUserLogged
const { response, data, error } = profileStore.isUserLogged
? await apiClient.POST(`/auth/${methodLink}/registration`, {
body: {
...to.query,
Expand All @@ -81,9 +81,10 @@ export const authHandler: NavigationGuard = async to => {
profileStore.updateToken();
toastStore.push({ title: 'Вы успешно вошли в аккаунт' });
return { path: '/profile', replace: true };
} else {
} else if (error) {
if (response.status === 401) {
const id_token = to.query.code;
const loginError = error as LoginError;
const id_token = loginError.id_token;

if (typeof id_token !== 'string') {
return {
Expand Down

0 comments on commit 621fdd5

Please sign in to comment.