Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function(ctx) {
// initialize feathers rest client
if(process.client) { // on browser pocess only
const { app, nuxtState } = ctx
const { protocol, host, port } = nuxtState.config
const storage = window.localStorage
const feathersClient = feathers()
feathersClient.hooks(hooks)
feathersClient.configure(rest(`${protocol}://${host}:${port}/api`).axios(app.$axios))
feathersClient.configure(authentication({ storage, service: 'logins', jwtStrategy: 'jwt', path: '/authentication' }))
// automatically logout once jwt expires
feathersClient.on('authenticated', ({user}) => setTimeout(feathersClient.logout, ( new Date(user.validTill) - Date.now() )) )
// automatically navigate to login page after logout
feathersClient.on('logout', () => app.router.push({ path: '/' }) )
const deleteCookie = (name) => document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;'
// logout if token invalidated
if(app.store.state.auth.errorOnAuthenticate) {
feathersClient.logout().then(() => {
deleteCookie('feathers-jwt')
app.store.commit(`auth/clearAuthenticateError`)
})