Skip to content

Commit

Permalink
fix: resolving requestChallenge hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnoW committed Jan 16, 2023
1 parent 2b1c40a commit 89f1dcd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/forty-dragons-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moralisweb3/auth': patch
'@moralisweb3/next': patch
---

Fix auth hooks for NextJs
24 changes: 24 additions & 0 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { makeVerify, VerifyEvmOptions, VerifyOptions, VerifySolOptions } from '.
import {
VerifyChallengeSolanaResponseAdapter,
VerifyChallengeEvmResponseAdapter,
RequestChallengeEvmResponseAdapter,
requestChallengeEvmOperation,
RequestChallengeEvmRequest,
RequestChallengeSolanaResponseAdapter,
requestChallengeSolanaOperation,
RequestChallengeSolanaRequest,
} from '@moralisweb3/common-auth-utils';
import { OperationResolver } from '@moralisweb3/api-utils';

export const BASE_URL = 'https://authapi.moralis.io';

Expand All @@ -27,6 +34,23 @@ export class Auth extends ApiModule {
// Nothing
}

// Client-side compatible operation, structured in a predictable way as defined in the operation
// TODO: generate in seperate package "client-evm-auth" (similar to client-evm-auth)
public readonly evm = {
requestChallengeEvm: (request: RequestChallengeEvmRequest): Promise<RequestChallengeEvmResponseAdapter> => {
return new OperationResolver(requestChallengeEvmOperation, this.baseUrl, this.core).fetch(request);
},
};

// Client-side compatible operation, structured in a predictable way as defined in the operation
// TODO: generate in seperate package "client-evm-auth" (similar to client-evm-auth)
public readonly solana = {
requestChallengeSol: (request: RequestChallengeSolanaRequest): Promise<RequestChallengeSolanaResponseAdapter> => {
return new OperationResolver(requestChallengeSolanaOperation, this.baseUrl, this.core).fetch(request);
},
};

// Resolves to requestChallengeEvm/requestChallengeSol depending on provided options (defaults to evm)
public requestMessage = (options: RequestMessageOptions) => makeRequestMessage(this.core)(options);

// Function overloading to make typescript happy
Expand Down

0 comments on commit 89f1dcd

Please sign in to comment.