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

feat: add options parameter to controller functions containing a query #753

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/controllers/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ export class AuthController extends BaseController {
login(
strategy: string,
credentials: JSONObject,
expiresIn?: string | number
expiresIn?: string | number,
options: ArgsAuthControllerLogin = {}
): Promise<string> {
const request = {
action: "login",
Expand All @@ -448,7 +449,12 @@ export class AuthController extends BaseController {
};

this.kuzzle.emit("beforeLogin");
return this.query(request, { queuable: false, timeout: -1, verb: "POST" })
return this.query(request, {
queuable: false,
timeout: -1,
verb: "POST",
...options,
})
.then((response) => {
if (this.kuzzle.cookieAuthentication) {
if (response.result.jwt) {
Expand Down Expand Up @@ -497,15 +503,15 @@ export class AuthController extends BaseController {
*
* @see https://docs.kuzzle.io/sdk/js/7/controllers/auth/logout
*/
async logout(): Promise<void> {
async logout(options: ArgsAuthControllerLogin = {}): Promise<void> {
this.kuzzle.emit("beforeLogout");
try {
await this.query(
{
action: "logout",
cookieAuth: this.kuzzle.cookieAuthentication,
},
{ queuable: false, timeout: -1 }
{ queuable: false, timeout: -1, ...options }
);
this._authenticationToken = null;
/**
Expand Down Expand Up @@ -700,6 +706,10 @@ export type ArgsAuthControllerUpdateSelf = ArgsDefault;

export type ArgsAuthControllerValidateMyCredentials = ArgsDefault;

export type ArgsAuthControllerLogin = ArgsDefault;

export type ArgsAuthControllerLogout = ArgsDefault;

export interface ArgsAuthControllerRefreshToken extends ArgsDefault {
expiresIn?: number | string;
}
15 changes: 10 additions & 5 deletions src/controllers/Security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,14 @@ export class SecurityController extends BaseController {
);
}

refresh(collection) {
return this.query({
action: "refresh",
collection,
});
refresh(collection, options: ArgsSecurityControllerRefresh = {}) {
return this.query(
{
action: "refresh",
collection,
},
options
);
}

replaceUser(_id, body, options: ArgsSecurityControllerReplaceUser = {}) {
Expand Down Expand Up @@ -809,3 +812,5 @@ export type ArgsSecurityControllerUpdateUser = ArgsDefault;
export type ArgsSecurityControllerUpdateUserMapping = ArgsDefault;

export type ArgsSecurityControllerValidateCredentials = ArgsDefault;

export type ArgsSecurityControllerRefresh = ArgsDefault;