Skip to content

Commit

Permalink
fix: update evm auth paths
Browse files Browse the repository at this point in the history
* refactor: move evm logic to evm-utils package

* style: fix naming of setupEvmApi

* fix: fix eslint config

* ci: cache format in nx

* ci: fix versioning of packages

* fix: remove debug function

* fix: import path

* fix: build of test-node typescript build

* ci: fix prettier version

* chore: update changeset

* fix: update evm auth paths

* chore: update parse server demo to show error

* docs: add changeset
  • Loading branch information
ErnoW authored Jul 27, 2022
1 parent 532234d commit b26d56b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changeset/plenty-readers-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'demo-parse-server-auth-server': minor
'@moralisweb3/auth': minor
---

Update endpoints for evm Authentication in Moralis.Auth to reflect api changes
1 change: 1 addition & 0 deletions demos/demo-parse-server-auth/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<h1>Demo Auth parse-server</h1>
</header>
<main>
<div id="error"></div>
<button class="btn" id="auth-metamask">Authenticate via Metamask</button>
<div id="user"></div>
</main>
Expand Down
14 changes: 11 additions & 3 deletions demos/demo-parse-server-auth/public/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const AUTH_API_URL = 'http://localhost:1337/api/auth';

const elError = document.getElementById('error');
const elUser = document.getElementById('user');
const elBtnMetamask = document.getElementById('auth-metamask');

const handleApiPost = async (endpoint, params) => {
const result = await axios.post(`${AUTH_API_URL}/${endpoint}`, params, {
headers: {
Expand Down Expand Up @@ -57,12 +61,16 @@ const handleAuth = async () => {
};

const renderUser = (user) => {
document.getElementById('user').innerHTML = user ? JSON.stringify(user, null, 2) : '';
elUser.innerHTML = user ? JSON.stringify(user, null, 2) : '';
};

const renderError = (error) => {
elError.innerHTML = error ? JSON.stringify(error.message, null, 2) : '';
};

function init() {
document.getElementById('auth-metamask').addEventListener('click', async () => {
handleAuth();
elBtnMetamask.addEventListener('click', async () => {
handleAuth().catch((error) => renderError(error));
});
}

Expand Down
7 changes: 7 additions & 0 deletions demos/demo-parse-server-auth/public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ h1 {
font-size: 1rem;
color: rgb(4, 24, 54);
}

#error {
margin-bottom: 1rem;
line-height: 1.2;
font-size: 1rem;
color: rgb(200, 31, 31);
}
12 changes: 6 additions & 6 deletions packages/auth/src/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/

export interface paths {
"/challenge": {
post: operations["initializeChallenge"];
"/challenge/request/evm": {
post: operations["Request Challenge (EVM)"];
};
"/challenge/complete": {
post: operations["completeChallenge"];
"/challenge/verify/evm": {
post: operations["Verify Challenge (EVM)"];
};
"/health": {
get: operations["HealthController_check"];
Expand Down Expand Up @@ -175,7 +175,7 @@ export interface components {
}

export interface operations {
initializeChallenge: {
"Request Challenge (EVM)": {
parameters: {};
responses: {
/** The back channel challenge containing the id to store on the api and the message to be signed by the user */
Expand All @@ -191,7 +191,7 @@ export interface operations {
};
};
};
completeChallenge: {
"Verify Challenge (EVM)": {
parameters: {};
responses: {
/** The token to be used to call the third party API from the client */
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/methods/requestMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AuthErrorCode, MoralisAuthError } from '@moralisweb3/core';
import { EvmAddress, EvmAddressish, EvmChain, EvmChainish } from '@moralisweb3/evm-utils';
import { initializeChallengeResolver } from '../resolvers/initializeChallenge';
import { initializeChallengeResolver } from '../resolvers/evmRequestChallenge';

export enum AuthNetwork {
EVM = 'evm',
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/methods/verify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertUnreachable } from '@moralisweb3/core';
import { completeChallengeResolver } from '../resolvers/completeChallenge';
import { completeChallengeResolver } from '../resolvers/evmVerifyChallenge';

export interface VerifyEvmOptions {
message: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { toCamelCase } from '@moralisweb3/core';
import { operations } from '../generated/types';
import { BASE_URL } from '../MoralisAuth';

type name = 'initializeChallenge';
type name = 'Request Challenge (EVM)';
type BodyParams = operations[name]['requestBody']['content']['application/json'];
type ApiParams = BodyParams;
const method = 'post';
Expand Down Expand Up @@ -31,8 +31,8 @@ const apiToResult = (apiData: ApiResult, params: Params) => {
};

export const initializeChallengeResolver = new ApiResolver({
name: 'initializeChallenge',
getUrl: (params: Params) => `${BASE_URL}/challenge/`,
name: 'Request Challenge (EVM)',
getUrl: (params: Params) => `${BASE_URL}/challenge/request/evm`,
apiToResult: apiToResult,
resultToJson: (data) => ({
...data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApiResolver } from '@moralisweb3/api-utils';
import { operations } from '../generated/types';
import { BASE_URL } from '../MoralisAuth';

type name = 'completeChallenge';
type name = 'Verify Challenge (EVM)';
type BodyParams = operations[name]['requestBody']['content']['application/json'];
type ApiParams = BodyParams;
type Params = ApiParams;
Expand All @@ -14,8 +14,8 @@ const bodyParams = ['message', 'signature'] as const;
type ApiResult = operations[name]['responses']['201']['content']['application/json'];

export const completeChallengeResolver = new ApiResolver({
name: 'completeChallenge',
getUrl: (params: Params) => `${BASE_URL}/challenge/complete`,
name: 'Verify Challenge (EVM)',
getUrl: (params: Params) => `${BASE_URL}/challenge/verify/evm`,
apiToResult: ({ chainId, ...data }: ApiResult) => ({
...data,
// TODO: revisit EVM logic once we know how authentication in other networks work
Expand Down

0 comments on commit b26d56b

Please sign in to comment.