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

Fixed id_token being taken from the wrong place #280

Merged
merged 4 commits into from
Nov 16, 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
16 changes: 8 additions & 8 deletions .github/workflows/main_commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 9.6.0
version: 9

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: 22
cache: "pnpm"

- name: Install
Expand All @@ -38,13 +38,13 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 7.26.3
version: 9

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: 22
cache: "pnpm"

- name: Install
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/pr_create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 7.26.3
version: 9

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: 22
cache: 'pnpm'

- name: Install
Expand All @@ -36,13 +36,13 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 7.26.3
version: 9

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: 22
cache: 'pnpm'

- name: Install
Expand Down
12 changes: 0 additions & 12 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
import pluginVue from 'eslint-plugin-vue';
import vueTsEslintConfig from '@vue/eslint-config-typescript';
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
...tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommended),
...pluginVue.configs['flat/recommended'],
Expand Down
20 changes: 8 additions & 12 deletions src/api/controllers/auth/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,15 @@ export function checkToken<F extends Func<any, any>>(
method: F
): Func<Promise<ReturnType<F>>, Parameters<F>> {
return async (...args: any[]) => {
try {
const { error } = await apiClient.GET('/auth/me');
throw error;
} catch (err) {
const error = err as apiError;
if (error && error.message === 'Forbidden') {
const { deleteToken } = useProfileStore();
const toastStore = useToastStore();
deleteToken();
router.push('/auth');
toastStore.push({ title: 'Сессия истекла' });
}
const { response: checkResponse } = await apiClient.GET('/auth/me');
if (!checkResponse.ok && checkResponse.status === 403) {
const { deleteToken } = useProfileStore();
const toastStore = useToastStore();
deleteToken();
router.push('/auth');
toastStore.push({ title: 'Сессия истекла' });
}

const response = await method(...args);
return response;
};
Expand Down
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
16 changes: 11 additions & 5 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,23 +62,29 @@ 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,
session_name: navigator.userAgent ?? UNKNOWN_DEVICE,
},
})
: await apiClient.POST(`/auth/${methodLink}/login`, { body: { ...to.query } });
: await apiClient.POST(`/auth/${methodLink}/login`, {
body: {
...to.query,
session_name: navigator.userAgent ?? UNKNOWN_DEVICE,
},
});

if (response.ok && data?.token) {
LocalStorage.set(LocalStorageItem.Token, data.token);
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