Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atlas integration for authentication, user settings, email confirmation, uploads #1654

Merged
merged 35 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0d004b7
chore(web): initial-wrapper-update
Harman-singh-waraich Jul 15, 2024
7172065
chore(web): update-queries
Harman-singh-waraich Jul 26, 2024
f454372
chore: update-netlify-functions-to-test-notifications
Harman-singh-waraich Jul 26, 2024
e985455
chore: update-lockfile
Harman-singh-waraich Jul 26, 2024
53b7b2a
fix(functions): fix-address-fetching-from-jwt-payload
Harman-singh-waraich Jul 26, 2024
33b818e
refactor(web): export-ensure-auth-as-default
Harman-singh-waraich Jul 26, 2024
ba2442a
refactor(web): structured-atlas-interaction
Harman-singh-waraich Aug 8, 2024
ddd06d1
refactor(web): code-smells
Harman-singh-waraich Aug 8, 2024
10efe92
refactor(web): remove-unused-import
Harman-singh-waraich Aug 8, 2024
5b41eda
Merge branch 'dev' into feat/atlas-siwe
Harman-singh-waraich Aug 9, 2024
cff6ee0
Merge branch 'dev' into feat/atlas-siwe
Harman-singh-waraich Aug 9, 2024
cc3a8be
feat(web): user-settings-integration
Harman-singh-waraich Aug 9, 2024
c58fb70
chore(web): remove-old-notifications-logic
Harman-singh-waraich Aug 9, 2024
ce7835f
refactor(web): refetch-on-address-change-and-set-empty-email-invalid
Harman-singh-waraich Aug 9, 2024
6ea2dd3
refactor(web): remove-previous-user-data-on-address-change
Harman-singh-waraich Aug 9, 2024
94b4714
Merge branch 'dev' into feat/atlas-siwe
Harman-singh-waraich Aug 21, 2024
cb8375b
chore(web): update-atlas-utils
Harman-singh-waraich Aug 21, 2024
b121de6
fix(web): upload-to-ipfs-token-fetch
Harman-singh-waraich Aug 22, 2024
39cf66d
chore: removal of the supabase dependencies
jaybuidl Sep 6, 2024
3d217da
feat(web): atlas-upload-to-ipfs-integration
Harman-singh-waraich Sep 12, 2024
b809aa0
chore(web): update-user-email-update-query
Harman-singh-waraich Sep 28, 2024
4f043cd
feat(web): email-verify-info
Harman-singh-waraich Oct 1, 2024
3397a63
feat(web): confirm-email-page
Harman-singh-waraich Oct 1, 2024
95ecb24
feat(web): email-verification-info-and-resend-button
Harman-singh-waraich Oct 1, 2024
3d0e0ca
fix(web): add-missing-property
Harman-singh-waraich Oct 1, 2024
4375993
refactor(web): remove-unnecessary-use-memo-usage
Harman-singh-waraich Oct 1, 2024
143d33f
chore(web): update-confirm-email-mutation
Harman-singh-waraich Oct 3, 2024
50ea26a
feat(web): confirmation-page-ui
Harman-singh-waraich Oct 3, 2024
16f8a17
refactor(web): refactor-message-configs
Harman-singh-waraich Oct 3, 2024
1ae4047
fix(web): fix-header-and-icon-color
Harman-singh-waraich Oct 3, 2024
9382b7f
Merge branch 'dev' into feat/atlas-siwe
Harman-singh-waraich Oct 10, 2024
4fa24cb
Merge branch 'feat/atlas-siwe' into feat/atlas-ipfs-upload
Harman-singh-waraich Oct 15, 2024
96a49cc
chore(web): new-ipfs-upload-flow
jaybuidl Oct 15, 2024
6f58f20
Merge pull request #1687 from kleros/feat/atlas-ipfs-upload
jaybuidl Oct 16, 2024
e72bd47
Merge branch 'dev' into feat/atlas-siwe
jaybuidl Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/.env.devnet-neo.public
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/6
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598
export REACT_APP_ARBITRATOR_TYPE=neo
export REACT_APP_ATLAS_URI=http://localhost:3000/graphql
export WALLETCONNECT_PROJECT_ID=
export ALCHEMY_API_KEY=
export NODE_OPTIONS='--max-old-space-size=7680'
1 change: 1 addition & 0 deletions web/.env.devnet-university.public
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/6
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598
export REACT_APP_ARBITRATOR_TYPE=university
export REACT_APP_ATLAS_URI=http://localhost:3000/graphql
export WALLETCONNECT_PROJECT_ID=
export ALCHEMY_API_KEY=
export NODE_OPTIONS='--max-old-space-size=7680'
1 change: 1 addition & 0 deletions web/.env.devnet.public
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/klero
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598
export REACT_APP_ATLAS_URI=http://localhost:3000/graphql
export WALLETCONNECT_PROJECT_ID=
export ALCHEMY_API_KEY=
export NODE_OPTIONS='--max-old-space-size=7680'
1 change: 1 addition & 0 deletions web/.env.local.public
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export REACT_APP_DEPLOYMENT=devnet
export REACT_APP_CORE_SUBGRAPH=http://localhost:8000/subgraphs/name/kleros/kleros-v2-core-local
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.thegraph.com/subgraphs/name/alcercu/templateregistrydevnet
export REACT_APP_ATLAS_URI=http://localhost:3000/graphql
export WALLETCONNECT_PROJECT_ID=
export ALCHEMY_API_KEY=
export NODE_OPTIONS='--max-old-space-size=7680'
1 change: 1 addition & 0 deletions web/.env.mainnet-neo.public
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export REACT_APP_DRT_ARBMAINNET_SUBGRAPH=https://api.studio.thegraph.com/query/6
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
export REACT_APP_GENESIS_BLOCK_ARBMAINNET=190274403
export REACT_APP_ARBITRATOR_TYPE=neo
export REACT_APP_ATLAS_URI=http://localhost:3000/graphql
export WALLETCONNECT_PROJECT_ID=
export ALCHEMY_API_KEY=
export NODE_OPTIONS='--max-old-space-size=7680'
1 change: 1 addition & 0 deletions web/.env.testnet.public
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export REACT_APP_DEPLOYMENT=testnet
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-core-testnet/version/latest
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest
export REACT_APP_STATUS_URL=https://kleros-v2.betteruptime.com/badge
export REACT_APP_ATLAS_URI=http://localhost:3000/graphql
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3842783
export WALLETCONNECT_PROJECT_ID=
export ALCHEMY_API_KEY=
Expand Down
117 changes: 0 additions & 117 deletions web/netlify/functions/authUser.ts

This file was deleted.

50 changes: 0 additions & 50 deletions web/netlify/functions/getNonce.ts

This file was deleted.

8 changes: 4 additions & 4 deletions web/netlify/middleware/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ export const authMiddleware = () => {
}

try {
const issuer = process.env.JWT_ISSUER ?? "Kleros"; // ex :- Kleros
const audience = process.env.JWT_AUDIENCE ?? "Court"; // ex :- Court, Curate, Escrow
const secret = process.env.JWT_SECRET;
// const secret = process.env.JWT_SECRET;
// TODO testing purpose
const secret = "u03tzA7Un9w+fetret343t6U2YaOlINle1E4avjc=";

if (!secret) {
throw new Error("Secret not set in environment");
}

const encodedSecret = new TextEncoder().encode(secret);

const { payload } = await jwt.jwtVerify(authToken, encodedSecret, { issuer, audience });
const { payload } = await jwt.jwtVerify(authToken, encodedSecret);

// add auth details to event
request.event.auth = payload;
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"siwe": "^2.3.1",
"styled-components": "^5.3.11",
"vanilla-jsoneditor": "^0.21.4",
"viem": "^2.1.0",
"viem": "^2.17.3",
"vite": "^5.2.10",
"wagmi": "^2.11.3"
}
Expand Down
22 changes: 10 additions & 12 deletions web/src/components/EnsureAuth.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo, useState } from "react";

import * as jwt from "jose";
import { SiweMessage } from "siwe";
import { createSiweMessage } from "viem/siwe";
import { useAccount, useChainId, useSignMessage } from "wagmi";

import { Button } from "@kleros/ui-components-library";
Expand Down Expand Up @@ -30,7 +30,7 @@ export const EnsureAuth: React.FC<IEnsureAuth> = ({ children, className }) => {

const payload = jwt.decodeJwt(authToken);

if ((payload?.id as string).toLowerCase() !== address.toLowerCase()) return false;
if ((payload?.sub as string)?.toLowerCase() !== address.toLowerCase()) return false;
if (payload.exp && payload.exp < Date.now() / 1000) return false;

return true;
Expand All @@ -41,7 +41,7 @@ export const EnsureAuth: React.FC<IEnsureAuth> = ({ children, className }) => {
setIsLoading(true);
if (!address) return;

const message = await createSiweMessage(address, "Sign In to Kleros with Ethereum.", chainId);
const message = await createMessage(address, "Sign In to Kleros with Ethereum.", chainId);

const signature = await signMessageAsync({ message });

Expand All @@ -52,9 +52,8 @@ export const EnsureAuth: React.FC<IEnsureAuth> = ({ children, className }) => {
signature,
message,
})
.then(async (res) => {
const response = await res.json();
setAuthToken(response["token"]);
.then(async (token) => {
setAuthToken(token);
})
.catch((err) => console.log({ err }))
.finally(() => setIsLoading(false));
Expand All @@ -77,16 +76,15 @@ export const EnsureAuth: React.FC<IEnsureAuth> = ({ children, className }) => {
);
};

async function createSiweMessage(address: `0x${string}`, statement: string, chainId: number = DEFAULT_CHAIN) {
async function createMessage(address: `0x${string}`, statement: string, chainId: number = DEFAULT_CHAIN) {
const domain = window.location.host;
const origin = window.location.origin;
const response = await getNonce(address);
const nonce = (await response.json()).nonce;
const nonce = await getNonce(address);

// signature is valid only for 10 mins
const expirationTime = new Date(Date.now() + 10 * 60 * 1000).toISOString();
const expirationTime = new Date(Date.now() + 10 * 60 * 1000);

const message = new SiweMessage({
const message = createSiweMessage({
domain,
address,
statement,
Expand All @@ -96,5 +94,5 @@ async function createSiweMessage(address: `0x${string}`, statement: string, chai
nonce,
expirationTime,
});
return message.prepareMessage();
return message;
}
Loading
Loading