directus / v8-archive

Directus Database API — Wraps Custom SQL Databases with a REST/GraphQL API
https://docs.directus.io/api/reference.html
505 stars 204 forks source link

Static token not working #2338

Open Niekvan opened 5 years ago

Niekvan commented 5 years ago

🐞 bug report

Description

When using the static access token from the Directus database in the SDK the following error appears: Uncaught TypeError: Cannot read property 'replace' of undefined

🔬 Minimal Reproduction

1. Fresh install of Nuxt
2. Install directus SDK
3. In the mounted function call 
`const client = new DirectusSDK({
  url: "https://demo-api.directus.app/",
  project: "_",
  storage: window.localStorage
});`

as described in the docs

🔥 Exception or Error


Uncaught TypeError: Cannot read property 'replace' of undefined

🌍 Your Environment

SDK Version: v5.3.4

Anything else relevant? Exact same issue as directus/sdk-js#61 ...

janbiasi commented 4 years ago

@Niekvan I think this error is caused inside of the JWT parse method as this is the only .replace call in the SDK ... https://github.com/directus/sdk-js/blob/1e13ca40b6f5f689e28bedb448285c116a542ba6/src/utils/payload.ts#L21-L24

Did you try to add your access token or mail/pass setting like described in https://github.com/directus/sdk-js/blob/develop/recipes/Starter.md ?

benhaynes commented 4 years ago

Any thoughts on this @rijkvanzanten ? Will this change based on the new auth flow?

rijkvanzanten commented 4 years ago

I think it's trying to read a non-existent token. It might wrongly assume the token was stored in localStorage, even if it isn't. @benhaynes could be introduced in the typescript refactor or my changes to support cookies

Niekvan commented 4 years ago

Hi,

I followed the exact instructions in the docs. Using email address and password works fine, but that is not an option for my use case. I fixed it by implementing my own version of the SDK without JWT, as this is not needed for access with the access_token.