Files
hoppscotch/packages/hoppscotch-sh-admin/src/main.ts
Joel Jacob Stephen 7a9f0c8756 refactor: improvements to the auth implementation in admin dashboard (#3444)
* refactor: abstract axios queries to a separate helper file

* chore: delete unnecessary file

* chore: remove unnecessary console logs

* refactor: updated urls for api and authquery helpers

* refactor: updated auth implementation

* refactor: use default axios instance

* chore: improve code readability

* refactor: separate instances for rest and gql calls

* refactor: removed async await from functions that do not need them

* refactor: removed probable login and probable user from the auth system

* refactor: better error handling in login component

* chore: deleted unnecessary files and restructured some files

* feat: new errors file with typed error message formats

* refactor: removed unwanted usage of async await

* refactor: optimizing the usage and return of promises in auth flow

* refactor: convey boolean return type in a better way

* chore: apply suggestions

* refactor: handle case when mailcatcher is not active

---------

Co-authored-by: nivedin <nivedinp@gmail.com>
Co-authored-by: James George <jamesgeorge998001@gmail.com>
2023-10-16 18:14:02 +05:30

66 lines
1.7 KiB
TypeScript

import { createApp } from 'vue';
import urql, { createClient, cacheExchange, fetchExchange } from '@urql/vue';
import { authExchange } from '@urql/exchange-auth';
import App from './App.vue';
// STYLES
import 'virtual:windi.css';
import '@hoppscotch/ui/style.css';
import '../assets/scss/themes.scss';
import '../assets/scss/styles.scss';
import '@fontsource-variable/inter';
import '@fontsource-variable/material-symbols-rounded';
import '@fontsource-variable/roboto-mono';
// END STYLES
import { HOPP_MODULES } from './modules';
import { auth } from './helpers/auth';
import { pipe } from 'fp-ts/function';
import * as O from 'fp-ts/Option';
import { GRAPHQL_UNAUTHORIZED } from './helpers/errors';
// Top-level await is not available in our targets
(async () => {
const app = createApp(App).use(
urql,
createClient({
url: import.meta.env.VITE_BACKEND_GQL_URL,
requestPolicy: 'network-only',
fetchOptions: () => {
return {
credentials: 'include',
};
},
exchanges: [
cacheExchange,
authExchange(async () => {
return {
addAuthToOperation(operation) {
return operation;
},
async refreshAuth() {
pipe(
await auth.performAuthRefresh(),
O.getOrElseW(() => auth.signOutUser(true))
);
},
didAuthError(error, _operation) {
return error.message === GRAPHQL_UNAUTHORIZED;
},
};
}),
fetchExchange,
],
})
);
// Initialize auth
await auth.performAuthInit();
// Initialize modules
HOPP_MODULES.forEach((mod) => mod.onVueAppInit?.(app));
app.mount('#app');
})();