Browse Source

refactor: cleanup and lint

pull/7569/head
Pranav C 8 months ago
parent
commit
7c4b8d70bd
  1. 1
      packages/nc-gui/composables/useApi/interceptors.ts
  2. 1
      packages/nc-gui/middleware/auth.global.ts
  3. 23
      packages/nocodb/src/controllers/auth/auth.controller.ts

1
packages/nc-gui/composables/useApi/interceptors.ts

@ -16,6 +16,7 @@ export function addAxiosInterceptors(api: Api<any>) {
axiosInstance.interceptors.request.use((config) => { axiosInstance.interceptors.request.use((config) => {
config.headers['xc-gui'] = 'true' config.headers['xc-gui'] = 'true'
// Add auth header only if signed in and if `xc-short-token` header is not present (for short-lived tokens used for token generation)
if (state.token.value && !config.headers['xc-short-token']) config.headers['xc-auth'] = state.token.value if (state.token.value && !config.headers['xc-short-token']) config.headers['xc-auth'] = state.token.value
if (!config.url?.endsWith('/user/me') && !config.url?.endsWith('/admin/roles') && state.previewAs?.value) { if (!config.url?.endsWith('/user/me') && !config.url?.endsWith('/admin/roles') && state.previewAs?.value) {

1
packages/nc-gui/middleware/auth.global.ts

@ -51,6 +51,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
await tryGoogleAuth(api, state.signIn) await tryGoogleAuth(api, state.signIn)
} }
/** if not signedIn try token population based on short-lived-token */
if (!state.signedIn.value) await tryShortTokenAuth(api, state.signIn) if (!state.signedIn.value) await tryShortTokenAuth(api, state.signIn)
/** if public allow all visitors */ /** if public allow all visitors */

23
packages/nocodb/src/controllers/auth/auth.controller.ts

@ -18,12 +18,10 @@ import type { AppConfig } from '~/interface/config';
import { UsersService } from '~/services/users/users.service'; import { UsersService } from '~/services/users/users.service';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { randomTokenString, setTokenCookie } from '~/services/users/helpers';
import { GlobalGuard } from '~/guards/global/global.guard'; import { GlobalGuard } from '~/guards/global/global.guard';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware'; import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { User } from '~/models';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard'; import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { PublicApiLimiterGuard } from '~/guards/public-api-limiter.guard'; import { PublicApiLimiterGuard } from '~/guards/public-api-limiter.guard';
@ -246,25 +244,6 @@ export class AuthController {
} }
async setRefreshToken({ res, req }) { async setRefreshToken({ res, req }) {
const userId = req.user?.id; await this.usersService.setRefreshToken({ res, req });
if (!userId) return;
const user = await User.get(userId);
if (!user) return;
const refreshToken = randomTokenString();
if (!user['token_version']) {
user['token_version'] = randomTokenString();
}
await User.update(user.id, {
refresh_token: refreshToken,
email: user.email,
token_version: user['token_version'],
});
setTokenCookie(res, refreshToken);
} }
} }

Loading…
Cancel
Save