kucherenko / strapi-plugin-passwordless

A plugin for Strapi Headless CMS that provides ability to sign-in/sign-up to an application by link had sent to email.
MIT License
77 stars 26 forks source link

Endpoint for Login with token results with error (v4) #4

Closed shumiyao closed 2 years ago

shumiyao commented 2 years ago

Tried v. 4.0.2 on Strapi version 4, mail user with login link works okay but Endpoint for Login with token results with an error.

http://localhost:1337/api/passwordless/login?loginToken=753816f096737f49b6534ec77f686ff1086d5cd2

strapi-plugin-passwordless was working with the previous version.

Is there anything additional that I need to do to get it working?

[2022-02-09 19:53:11.955] error: Unexpected token o in JSON at position 1
SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at Object.login (/development/</anonymous>node_modules/strapi-plugin-passwordless/server/controllers/auth.js:65:21)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async returnBodyMiddleware (/development/</anonymous>node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
    at async policiesMiddleware (/development/</anonymous>node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
    at async serve (/development/</anonymous>node_modules/koa-static/index.js:59:5)
    at async returnBodyMiddleware (/development/</anonymous>node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
    at async policiesMiddleware (/development/</anonymous>node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
    at async /development/</anonymous>node_modules/@strapi/strapi/lib/middlewares/body.js:24:7
    at async /development/</anonymous>node_modules/@strapi/strapi/lib/middlewares/logger.js:22:5
    at async /development/</anonymous>node_modules/@strapi/strapi/lib/middlewares/powered-by.js:16:5
    at async cors (/development/</anonymous>node_modules/@koa/cors/index.js:56:32)
    at async /development/</anonymous>node_modules/@strapi/strapi/lib/middlewares/errors.js:13:7
kucherenko commented 2 years ago

Thank you for the report, will fix it

shumiyao commented 2 years ago

Thank you

kucherenko commented 2 years ago

I've investigated the issue, looks like you have no field context in token content-type, probably you should recreate token table or add context to it manually, the type of context is json.

kucherenko commented 2 years ago

published strapi-plugin-passwordless@4.0.3, in the version error not happen if context is not exists

shumiyao commented 2 years ago

@kucherenko

Thank you very much. v 4.0.3 is working without any problems. I did not have to touch the tokens table.