How to use the @commercetools/sdk-middleware-auth.createAuthMiddlewareForAnonymousSessionFlow function in @commercetools/sdk-middleware-auth

To help you get started, we’ve selected a few @commercetools/sdk-middleware-auth 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 commercetools / nodejs / integration-tests / sdk / auth-middleware.it.js View on Github external
const anonymousId = `${Date.now()}-bar`
      const userConfig = {
        ...apiConfig,
        ...{ scopes: [`manage_project:${projectKey}`] },
        ...{
          credentials: {
            clientId: apiConfig.credentials.clientId,
            clientSecret: apiConfig.credentials.clientSecret,
            anonymousId,
          },
        },
        fetch,
      }
      const client = createClient({
        middlewares: [
          createAuthMiddlewareForAnonymousSessionFlow(userConfig),
          httpMiddleware,
        ],
      })
      const cartMock = {
        currency: 'EUR',
      }
      return client
        .execute({
          // creates a cart that is tied to the logged in anonymous token
          uri: `/${projectKey}/me/carts`,
          method: 'POST',
          body: cartMock,
        })
        .then(({ body: cart }) => {
          expect(cart).toHaveProperty('anonymousId', anonymousId)
          return client.execute({