From 5c9c7575f21355a4b796d75f76cbce70361000f4 Mon Sep 17 00:00:00 2001 From: Nabarun Date: Sat, 19 Oct 2024 13:06:09 +0000 Subject: [PATCH] Set user email with ETH address while authenticating (#5) Part of [Service provider auctions for web deployments](https://www.notion.so/Service-provider-auctions-for-web-deployments-104a6b22d47280dbad51d28aa3a91d75) Reviewed-on: https://git.vdb.to/cerc-io/snowballtools-base/pulls/5 Co-authored-by: Nabarun Co-committed-by: Nabarun --- packages/backend/environments/local.toml.example | 3 +++ packages/backend/src/routes/auth.ts | 7 +++++-- packages/backend/src/service.ts | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/backend/environments/local.toml.example b/packages/backend/environments/local.toml.example index a6280060..2c8eca54 100644 --- a/packages/backend/environments/local.toml.example +++ b/packages/backend/environments/local.toml.example @@ -4,8 +4,11 @@ gqlPath = "/graphql" [server.session] secret = "" + # Frontend webapp URL origin appOriginUrl = "http://localhost:3000" + # Set to true if server running behind proxy trustProxy = false + # Backend URL hostname domain = "localhost" [database] diff --git a/packages/backend/src/routes/auth.ts b/packages/backend/src/routes/auth.ts index e528f0dc..3c4aa4bb 100644 --- a/packages/backend/src/routes/auth.ts +++ b/packages/backend/src/routes/auth.ts @@ -46,6 +46,9 @@ router.post('/authenticate', async (req, res) => { } }); +// +// SIWE Auth +// router.post('/validate', async (req, res) => { const { message, signature } = req.body; const { success, data } = await new SiweMessage(message).verify({ @@ -61,11 +64,11 @@ router.post('/validate', async (req, res) => { if (!user) { const newUser = await service.createUser({ ethAddress: data.address, - email: '', - name: '', + email: `${data.address}@example.com`, subOrgId: '', turnkeyWalletId: '', }); + // SIWESession from the web3modal library requires both address and chain ID req.session.address = newUser.id; req.session.chainId = data.chainId; diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 5a5286c9..728a067b 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -378,7 +378,7 @@ export class Service { } async createUser(params: { - name: string; + name?: string; email: string; subOrgId: string; ethAddress: string;