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

[Bug]: Strategy: "apiToken" #86

Closed
foodiecompany opened this issue Jan 21, 2024 · 9 comments · Fixed by #87
Closed

[Bug]: Strategy: "apiToken" #86

foodiecompany opened this issue Jan 21, 2024 · 9 comments · Fixed by #87
Labels
bug Something isn't working

Comments

@foodiecompany
Copy link

What issue are you experiencing?

The apiToken strategy encounters issues when modifying specific data, and the cause of this problem is currently unknown. However, a workaround is available by switching to the JWT strategy, which allows the messages for changes to function as expected. Your assistance in resolving this matter would be greatly appreciated. Thank you.

Steps To Reproduce

CMS Strapi

Plugin config

const config = {
  io: {
    enabled: true,
    config: {
      socket: {
        serverOptions: {
          cors: {
            origin: [env("CLIENT_URL"), env("STAFF_URL")],
            methods: ["GET", "POST"],
            credentials: true,
          },
        },
      },
      contentTypes: [
        "api::table.table",
        "api::request-staff-event.request-staff-event",
        "api::order.order",
        "api::cart.cart",
      ],
      events: [
        {
          name: "connection",
          handler: ({ strapi }, socket) => {
            strapi.log.info(`[io] new connection with id ${socket.id}`);
          },
        },
      ],
    },
  },

}

Token Configuration

image

FrontEnd NextJS

const so = io(config.apiUrl, {
    withCredentials: true,
    auth: {
      strategy: "apiToken",
      token: getConfig().guestToken
    }
  });

Networking

Payload
image

Responce
image

Comunications
image

What version of the plugin are you using?

2.0.5

What strapi version are you using?

4.17.1

@ComfortablyCoding
Copy link
Contributor

ComfortablyCoding commented Jan 21, 2024

Thanks for the report! Can you expand on what you mean by "The apiToken strategy encounters issues when modifying specific data"? The reproduction steps are not so clear to me.

How are you sending/modifying the data? What are you expecting to receive back vs what you actually receiving? Is their any custom function that is handling it server side? Any other possible relevant info?

@foodiecompany
Copy link
Author

Sure,
When the auth type jwt all works fine but, when I change to apiToken does.

As previously mentioned, we have a collectionType: api::table.table, containing fields like no, descriptions, status, etc.. Everything functions correctly when modifying the 'status' field under the 'jwt' strategy. However, issues arise when using the 'apiToken' strategy.

@ComfortablyCoding
Copy link
Contributor

ComfortablyCoding commented Jan 21, 2024

What "issues" arise when using apiToken? "Issues arise" is a fairly broad term and hard to attempt to reproduce.

@foodiecompany
Copy link
Author

Our attached handler is not being called

Example:

socket.on("table:update", (table) => {

});

The event table:update is not triggered when we use the apiToken strategy.

@ComfortablyCoding
Copy link
Contributor

Thank you for the clarification, I will see if I can reproduce this issue

@maxval1
Copy link

maxval1 commented Jan 22, 2024

Additionally, we have webhooks.populateRelations set to true because of this issue: #82

@codyparnell
Copy link
Contributor

I found the cause of this issue, as i was running into the same problem.

I created a pull request with my fix

Basically this was an issue that only effected api tokens with an unlimited duration. The solution was properly querying these tokens.

@ComfortablyCoding
Copy link
Contributor

ComfortablyCoding commented Jan 23, 2024

Thanks Cody! This should be fixed via #87 in the latest relase (v2.0.6)

@ComfortablyCoding ComfortablyCoding added the bug Something isn't working label Jan 23, 2024
@foodiecompany
Copy link
Author

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants