Skip to content

Commit

Permalink
refactor: add-deploy-uri-check
Browse files Browse the repository at this point in the history
  • Loading branch information
Harman-singh-waraich committed May 1, 2024
1 parent 45e7ee8 commit 15a3d22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions web/netlify/functions/authUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SiweMessage } from "siwe";
import { DEFAULT_CHAIN } from "consts/chains";
import { ETH_SIGNATURE_REGEX } from "consts/index";

import { netlifyUri, netlifyDeployUri } from "src/generatedNetlifyInfo.json";
import { netlifyUri, netlifyDeployUri, netlifyDeployPrimeUri } from "src/generatedNetlifyInfo.json";
import { Database } from "src/types/supabase-notification";

const authUser = async (event) => {
Expand Down Expand Up @@ -37,8 +37,16 @@ const authUser = async (event) => {

const siweMessage = new SiweMessage(message);

if (netlifyUri && netlifyUri !== siweMessage.uri && netlifyDeployUri && netlifyDeployUri !== siweMessage.uri) {
console.debug(`Invalid URI: expected ${netlifyUri} but got ${siweMessage.uri}`);
if (
!(
(netlifyUri && netlifyUri === siweMessage.uri) ||
(netlifyDeployUri && netlifyDeployUri === siweMessage.uri) ||
(netlifyDeployPrimeUri && netlifyDeployPrimeUri === siweMessage.uri)
)
) {
console.debug(
`Invalid URI: expected one of [${netlifyUri} ${netlifyDeployUri} ${netlifyDeployPrimeUri}] but got ${siweMessage.uri}`
);
throw new Error(`Invalid URI`);
}

Expand Down
2 changes: 1 addition & 1 deletion web/scripts/generateBuildInfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

jq -n --arg primeUri "$DEPLOY_PRIME_URL" --arg uri "$URL" '{ netlifyDeployUri: $primeUri, netlifyUri: $uri }' > src/generatedNetlifyInfo.json
jq -n --arg primeUri "$DEPLOY_PRIME_URL" --arg uri "$URL" --arg deployUri "$DEPLOY_URL" '{ netlifyDeployPrimeUri: $primeUri, netlifyUri: $uri, netlifyDeployUri: $deployUri }' > src/generatedNetlifyInfo.json
node $SCRIPT_DIR/gitInfo.js

0 comments on commit 15a3d22

Please sign in to comment.