Skip to content

Commit

Permalink
feat: added login user method
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth9890 committed Jul 3, 2024
1 parent e162e28 commit ac4ce47
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions src/modules/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
CreateUserInput,
loginUserMutationMutationVariables,
Sdk,
SignedWalletNonceInput,
} from '../../../gatewaySdk/sources/Gateway';
import { Chain, SignCipherEnum } from '../../common/enums';
import { errorHandler, getChain } from '../../helpers/helper';
Expand Down Expand Up @@ -96,34 +96,20 @@ export class Auth {
}

/**
* The function generates a nonce and message by making a async query to the Gateway Protocol.
* @param {string} wallet - The input parameter is of type string which represent wallet
* @param {SignCipherEnum?} cipher - The input parameter is of type string which represent wallet
* @returns the result of the `generateNonce` method, is a string which is a object of type generateNonce_mutationMutation
* Use this method to generate a new auth token
* This function logs in a user by validating input data and calling a login mutation.
* @param {loginUserMutationMutationVariables} input - The `loginUser` function takes an input object
* of type `loginUserMutationMutationVariables`. This input object likely contains the necessary data
* for logging in a user, such as the signing cipher, signing key, and signature.
* @returns The `loginUser` object is being returned from the `loginUserMutation` function call.
*/
public async generateNonce(wallet: string, cipher?: SignCipherEnum) {
public async loginUser(input: loginUserMutationMutationVariables) {
try {
const chain: Chain = getChain(cipher);
this.validationService.validateWalletAddress(wallet, chain);
return await this.sdk.generateNonceMutation({
input: { wallet, cipher },
});
} catch (error) {
throw new Error(errorHandler(error));
}
}

/**
* The function generates a jwt by making a async query to the Gateway Protocol.
* @param {SignedWalletNonceInput} input - The input parameter is of type SignedWalletNonceInput
* @returns the result of the `refreshToken` method, is a string which has jwt
*/
public async refreshToken(input: SignedWalletNonceInput) {
try {
const chain: Chain = getChain(input.cipher as SignCipherEnum);
const chain: Chain = getChain(input.signingCipher as SignCipherEnum);
this.validationService.validateWalletAddress(input.signingKey, chain);
this.validationService.validateString(input.signature);
return (await this.sdk.refreshTokenMutation({ input })).refreshToken;

return (await this.sdk.loginUserMutation(input)).loginUser;
} catch (error) {
throw new Error(errorHandler(error));
}
Expand Down

0 comments on commit ac4ce47

Please sign in to comment.