1

I'm trying to login using the msw library and following the Redux docs. Then I want to get the user auth token. I'm sending request for login but idk how to get auth token if logged in. Is the structure in the example correct for login? If not, how should it be

export const handlers = [
  rest.post("/login", (req, res, ctx) => {
    return res(
      ctx.json({
        id: "1234",
        firstName: "John",
        lastName: "Maverick",
      })
    );
  })

const server = setupServer(...handlers);

// Enable API mocking before tests.
beforeAll(() => server.listen());

// Reset any runtime request handlers we may add during the tests.
afterEach(() => server.resetHandlers());

// Disable API mocking after the tests are done.
afterAll(() => server.close());
hsngdr
  • 21
  • 5
  • I will open a bounty for this question... Basically cuz I want to implement cache on the response, and maybe ctx object can help me :) – ValRob Oct 25 '22 at 07:39
  • 1
    Hey @ValRob , I made a small project for this problem. I'm giving a link if you want to check it out. I hope it solves your problem. :) [Github](https://github.com/hsngdr/Redux-CreateAsyncThunk-Testing-With-Msw) – hsngdr Oct 26 '22 at 09:46
  • hsngdr, thanks i will check out – ValRob Oct 27 '22 at 11:49

0 Answers0