Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript example? #632

Closed
francoism90 opened this issue Feb 18, 2021 · 7 comments
Closed

Typescript example? #632

francoism90 opened this issue Feb 18, 2021 · 7 comments

Comments

@francoism90
Copy link
Contributor

// src/boot/auth.ts
import { boot } from 'quasar/wrappers'
import { api } from './axios'
import { createAuth } from '@websanova/vue-auth/dist/v3/vue-auth'
import * as driverAuthBearer from '@websanova/vue-auth/dist/v3/vue-auth'
import * as driverHttpAxios from '@websanova/vue-auth/src/drivers/http/axios.1.x'
import * as driverRouterVueRouter from '@websanova/vue-auth/src/drivers/router/vue-router.2.x'

export default boot(({ app, router }) => {
  app.use(createAuth({
    plugins: {
      http: api,
      router: router
    },
    drivers: {
      http: driverHttpAxios,
      auth: driverAuthBearer,
      router: driverRouterVueRouter,
    },
    options: {
      rolesKey: 'type',
      notFoundRedirect: { name: 'user-account' }
    }
  }))
})

Results in a lot of TypeScript errors:

Could not find a declaration file for module '@websanova/vue-auth/dist/v3/vue-auth'. '/srv/http/project/app/node_modules/@websanova/vue-auth/dist/v3/vue-auth.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/websanova__vue-auth` if it exists or add a new declaration (.d.ts) file containing `declare module '@websanova/vue-auth/dist/v3/vue-auth';`
...

Unsafe assignment of an any value.

I know this is written in JavaScript, I'm just searching for a workaround for these issues. I'm unable to add ignore the file as it isn't allowed and it's best practice. Do you have any good ideas? :)

Thanks!

@websanova
Copy link
Owner

Not quite sure, I'm not using TS, there was definitions file added a while ago, but I haven't checked that in a while.

https://github.com/websanova/vue-auth/blob/master/types/index.d.ts

Maybe start there?

@francoism90
Copy link
Contributor Author

@websanova Thanks! Unfortunately I'm still learning TS, it seems a few things are missing from the types (createAuth, drivers, etc.), but I'm not that well knowledge about what should be defined, sorry.

@websanova
Copy link
Owner

ya, I think it just needs a few minor updates, should be able to follow what's there if you need to get it working right away.

@abraxxa
Copy link

abraxxa commented Mar 26, 2021

I'm also interested in a typescript example.

@websanova
Copy link
Owner

@abraxxa Well there is one right there in the repo, as mentioned above it may have some minor issues from some recent updates.

@abraxxa
Copy link

abraxxa commented Mar 27, 2021

Are you referring to the index.d.ts file?
One issue is that createAuth doesn‘t return a typed object.
Another that some types include ‚any‘ which results in errors.
I‘m also a beginner regarding typescript and would like someone more experienced to join the discussion.

@abraxxa
Copy link

abraxxa commented Feb 18, 2022

I'm still struggling to get this working.
The type definition for createAuth is now in the index.d.ts file, but it isn't used by the typescript compiler.
How do I have to import createAuth and the drivers to make that work?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants