Skip to content

Commit

Permalink
Removed register functionally and fixed some minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcvelmer committed Aug 29, 2024
1 parent 4e8a463 commit b505dac
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 63 deletions.
35 changes: 0 additions & 35 deletions src/api/remote-signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@ import axios from 'axios';
import { API } from './api';

enum RemoteSignerAPIMethods {
REGISTER = '/users',
LOGIN = '/auth/login',
REFRESH = '/auth/refresh',
ADDRESSES = '/auth/addresses',
SIGN_TX = '/transactions',
SIGN = '/transactions/message',
}

export interface IRemoteSignerRegisterResponse {
/**
* The JWT token
*/
token: string;
}

export interface IRemoteSignerLoginResponse {
/**
* The JWT token
Expand Down Expand Up @@ -70,33 +62,6 @@ export abstract class RemoteSignerAPI extends API {
super();
}

/**
* Registers a new user using email and password.
*
* @param url - API endpoint URL
* @param email - The email address
* @param firstName - The first name
* @param lastName - The last name
* @param password - The password
*/
public static register(
url: string,
email: string,
firstName: string,
lastName: string,
password: string
): Promise<IRemoteSignerRegisterResponse> {
return axios
.post<IRemoteSignerRegisterResponse>(url + RemoteSignerAPIMethods.REGISTER, {
email,
firstName,
lastName,
password,
})
.then((response) => response.data)
.catch(this.isApiError);
}

/**
* Logs in a user using email and password.
*
Expand Down
21 changes: 2 additions & 19 deletions src/services/remote-signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@ export class RemoteSignerService extends Service implements RemoteSignerServiceP
this.remoteSigner = params.remoteSigner;
}

/**
* Registers a new user using email and password.
*
* @param email - The email address
* @param firstName - The first name
* @param lastName - The last name
* @param password - The password
* @returns The JWT token
*/
register(email: string, firstName: string, lastName: string, password: string): Promise<string> {
invariant(this.remoteSigner.url, 'No URL set');
invariant(this.remoteSigner.credentials, 'No authentication data set');
return RemoteSignerAPI.register(this.remoteSigner.url, email, firstName, lastName, password).then(
(response) => response.token
);
}

/**
* Logs in to the remote signer.
*
Expand All @@ -49,8 +32,8 @@ export class RemoteSignerService extends Service implements RemoteSignerServiceP
login(credentials?: RemoteSignerCredentials): Promise<string> {
invariant(this.remoteSigner.url, 'No URL set');
const login = {
email: credentials.email ?? this.remoteSigner.credentials.email,
password: credentials.password ?? this.remoteSigner.credentials.password,
email: credentials.email ?? this.remoteSigner.credentials?.email,
password: credentials.password ?? this.remoteSigner.credentials?.password,
};
return RemoteSignerAPI.login(this.remoteSigner.url, login.email, login.password).then((response) => response.token);
}
Expand Down
11 changes: 2 additions & 9 deletions src/types/remote-signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,10 @@ export class RemoteSigner extends Signer {
this.remoteSignerService = new RemoteSignerService({ remoteSigner: this });
}

async register(email: string, firstName: string, lastName: string, password: string): Promise<string> {
return this.remoteSignerService.register(email, firstName, lastName, password).then((token) => {
this.token = token;
return token;
});
}

async login(credentials?: RemoteSignerCredentials): Promise<string> {
const login = {
email: credentials?.email ?? this.credentials.email,
password: credentials?.password ?? this.credentials.password,
email: credentials?.email ?? this.credentials?.email,
password: credentials?.password ?? this.credentials?.password,
};
return this.remoteSignerService.login(login).then((token) => {
this.token = token;
Expand Down

0 comments on commit b505dac

Please sign in to comment.