Open
Description
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,
- login
- 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
Labels
No labels