Skip to content

A way to set defaults of headers / query params #336

Open
@felixmosh

Description

@felixmosh

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

app.inject().setDefaults({headers: {auth: 'Beaere MY_ACCESS_TOKEN'}})

Motivation

I want to simplify the following flow,

  1. login
  2. make auth required request

currenly I'm saving the accessToken from the login response, and then attaching it to each one of the following request.
If there was some method of assigning a default header value, it can be used after login.

Example

const response = await app.inject({ method: 'post', url: '/admin/auth/login', body });
const { payload, errors } = response.json<{ payload: IAuthToken; errors: string[] }>();
expect(response.statusCode).toEqual(200);
expect(errors).toHaveLength(0);

if (payload) {
  app.inject().setDefaults({ headers: { authorization: 'Bearer ${payload.accessToken}' } });
}

const addAdminResponse = await app.inject({method: 'post', url: '/admin/admins/add', body: { ... }}); // this request requires auth token header.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions