Vue wrapper files used to check authorization for users throughout Mcity apps.
Mcity-vue3-auth uses a number of open source projects to work properly:
- Create file
.env.local
if it does not already exist. - Add the following variables to this file.
VITE_MIXPANEL_TOKEN=value
VITE_OAUTH_KEY=value
VITE_HOST=http://localhost:8080
VITE_OAUTH_SERVER=https://keys.um.city/
VITE_REDIRECT_URI=http://localhost:8080/authorized
VITE_OAUTH_SCOPE=email+roles+[value]
- After the default router view in the
App.vue
template, add a named router view toApp.vue
with<router-view name="auth"/>
- Import
authRefresh
component withimport authRefresh from '@mcity/mcity-vue3-auth/src/components/RefreshAuthiFrame.vue'
- In the template of
App.vue
, after the router-view, add the importedauthRefresh
component
<auth-refresh
v-if="getShowIframe"
>
</auth-refresh>
- Import
AuthComponent
into the Vue Routerindex.js
file withimport 'AuthComponent' from '@mcity/mcity-vue3-auth/src/components/AuthComponent.vue'
- Add a new top-level route,
/authorized
{
path: '/authorized',
name: 'OverviewAuth',
components: {
auth: AuthComponent
},
meta: {
authorized: true
}
},
- Import the
checkRequiresAuth
function into the Vue routerindex.js
file withimport { checkRequiresAuth } from '@mcity/mcity-vue3-auth/src/router/beforeEachHooks'
- Add the following line before the export of the router:
router.beforeEach(checkRequiresAuth)
- Add the
session
Pinia module to the store.
import useSessionStore from '@mcity/mcity-vue3-auth/src/store/session'
export const useStore = defineStore('store', () => {
const session = useSessionStore()
return { projects, getProjectByKey, session }
})
- After making code changes, rerun babel by running
npm run build
- Make sure to commit these built files.
- Updated the version number and push to main. Github actions will publish changes to NPM.