How to use the @feathersjs/rest-client function in @feathersjs/rest-client

To help you get started, we’ve selected a few @feathersjs/rest-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github feathers-nuxt / template-app / template / src / client / utils / initClient.js View on Github external
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`)
      })

@feathersjs/rest-client

REST client services for different Ajax libraries

MIT
Latest version published 2 months ago

Package Health Score

92 / 100
Full package analysis

Popular @feathersjs/rest-client functions