refactor: have login route to pubkey login if it is configured. have loginPubkey return a LoginResponse
This commit is contained in:
parent
ab31ab6345
commit
6d5c27c972
|
@ -105,6 +105,10 @@ export class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(): Promise<LoginResponse> {
|
async login(): Promise<LoginResponse> {
|
||||||
|
if (!this._options.privateKey) {
|
||||||
|
return this.loginPubkey();
|
||||||
|
}
|
||||||
|
|
||||||
return this.post<LoginResponse>("/api/v1/auth/login", {
|
return this.post<LoginResponse>("/api/v1/auth/login", {
|
||||||
email: this._options.email,
|
email: this._options.email,
|
||||||
password: this._options.password,
|
password: this._options.password,
|
||||||
|
@ -131,7 +135,7 @@ export class Client {
|
||||||
return json.status as boolean;
|
return json.status as boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loginPubkey(): Promise<void> {
|
async loginPubkey(): Promise<LoginResponse> {
|
||||||
if (!this._options.privateKey) {
|
if (!this._options.privateKey) {
|
||||||
throw new Error("Private key is required");
|
throw new Error("Private key is required");
|
||||||
}
|
}
|
||||||
|
@ -158,6 +162,8 @@ export class Client {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.jwtSessionKey = loginRet.token;
|
this.jwtSessionKey = loginRet.token;
|
||||||
|
|
||||||
|
return { token: loginRet.token };
|
||||||
}
|
}
|
||||||
|
|
||||||
logout(request: LogoutRequest): Promise<void> {
|
logout(request: LogoutRequest): Promise<void> {
|
||||||
|
|
Loading…
Reference in New Issue