diff --git a/packages/hoppscotch-sh-admin/src/helpers/auth.ts b/packages/hoppscotch-sh-admin/src/helpers/auth.ts index a245d4579..850310b03 100644 --- a/packages/hoppscotch-sh-admin/src/helpers/auth.ts +++ b/packages/hoppscotch-sh-admin/src/helpers/auth.ts @@ -61,17 +61,21 @@ async function logout() { } async function signInUserWithGithubFB() { - window.location.href = `${import.meta.env.VITE_BACKEND_API_URL}/auth/github`; + window.location.href = `${ + import.meta.env.VITE_BACKEND_API_URL + }/auth/github?redirect_uri=${import.meta.env.VITE_ADMIN_URL}`; } async function signInUserWithGoogleFB() { - window.location.href = `${import.meta.env.VITE_BACKEND_API_URL}/auth/google`; + window.location.href = `${ + import.meta.env.VITE_BACKEND_API_URL + }/auth/google?redirect_uri=${import.meta.env.VITE_ADMIN_URL}`; } async function signInUserWithMicrosoftFB() { window.location.href = `${ import.meta.env.VITE_BACKEND_API_URL - }/auth/microsoft`; + }/auth/microsoft?redirect_uri=${import.meta.env.VITE_ADMIN_URL}`; } async function getInitialUserDetails() { @@ -215,7 +219,7 @@ async function elevateUser() { async function sendMagicLink(email: string) { const res = await axios.post( - `${import.meta.env.VITE_BACKEND_API_URL}/auth/signin`, + `${import.meta.env.VITE_BACKEND_API_URL}/auth/signin?origin=admin`, { email, }, diff --git a/packages/hoppscotch-sh-admin/src/modules/admin.ts b/packages/hoppscotch-sh-admin/src/modules/admin.ts index 5e4df5911..b25fd58d6 100644 --- a/packages/hoppscotch-sh-admin/src/modules/admin.ts +++ b/packages/hoppscotch-sh-admin/src/modules/admin.ts @@ -6,11 +6,28 @@ const isAdmin = () => { return user ? user.isAdmin : false; }; +const GUEST_ROUTES = ['index', 'magic-link']; + +const isGuestRoute = (to: unknown) => GUEST_ROUTES.includes(to as string); + +/** + * @module routers + */ + +/** + * @function + * @name onBeforeRouteChange + * @param {object} to + * @param {object} from + * @param {function} next + * @returns {void} + */ + export default { onBeforeRouteChange(to, from, next) { - if (to.name !== 'index' && !isAdmin()) { + if (!isGuestRoute(to.name) && !isAdmin()) { next({ name: 'index' }); - } else if (to.name === 'index' && isAdmin()) { + } else if (isGuestRoute(to.name) && isAdmin()) { next({ name: 'dashboard' }); } else { next(); diff --git a/packages/hoppscotch-sh-admin/src/pages/magic-link.vue b/packages/hoppscotch-sh-admin/src/pages/magic-link.vue new file mode 100644 index 000000000..0ba829092 --- /dev/null +++ b/packages/hoppscotch-sh-admin/src/pages/magic-link.vue @@ -0,0 +1,35 @@ + + + + + +meta: + layout: empty +