refactor: have login route to pubkey login if it is configured. have loginPubkey return a LoginResponse

This commit is contained in:
Derrick Hammer 2023-06-24 02:47:57 -04:00
parent ab31ab6345
commit 6d5c27c972
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 1 deletions

View File

@ -105,6 +105,10 @@ export class Client {
}
async login(): Promise<LoginResponse> {
if (!this._options.privateKey) {
return this.loginPubkey();
}
return this.post<LoginResponse>("/api/v1/auth/login", {
email: this._options.email,
password: this._options.password,
@ -131,7 +135,7 @@ export class Client {
return json.status as boolean;
}
async loginPubkey(): Promise<void> {
async loginPubkey(): Promise<LoginResponse> {
if (!this._options.privateKey) {
throw new Error("Private key is required");
}
@ -158,6 +162,8 @@ export class Client {
);
this.jwtSessionKey = loginRet.token;
return { token: loginRet.token };
}
logout(request: LogoutRequest): Promise<void> {