-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
193 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { cookies } from "next/headers"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import crypto from "crypto"; | ||
|
||
export function GET(request: NextRequest) { | ||
const uuid = crypto.randomUUID().replace(/-/g, ""); | ||
const nonce = crypto | ||
.createHmac("sha256", process.env.NONCE_SECRET || "") | ||
.update(uuid) | ||
.digest("hex"); | ||
|
||
cookies().set("siwe", nonce, { secure: true }); | ||
|
||
return NextResponse.json({ nonce }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { cookies } from "next/headers"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { MiniAppWalletAuthSuccessPayload, verifySiweMessage } from "@worldcoin/minikit-js"; | ||
|
||
interface IRequestPayload { | ||
payload: MiniAppWalletAuthSuccessPayload; | ||
nonce: string; | ||
} | ||
|
||
export async function POST(req: NextRequest) { | ||
const { payload, nonce } = (await req.json()) as IRequestPayload; | ||
if (nonce != cookies().get("siwe")?.value) { | ||
return NextResponse.json({ | ||
status: "error", | ||
isValid: false, | ||
message: "Invalid nonce", | ||
}); | ||
} | ||
try { | ||
const validMessage = await verifySiweMessage(payload, nonce); | ||
return NextResponse.json({ | ||
status: "success", | ||
isValid: validMessage.isValid, | ||
}); | ||
} catch (error: any) { | ||
return NextResponse.json({ | ||
status: "error", | ||
isValid: false, | ||
message: error.message, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/nextjs-app/src/components/eruda/eruda-provider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use client"; | ||
|
||
import { ReactNode, useEffect } from "react"; | ||
import eruda from "eruda"; | ||
|
||
export const Eruda = (props: { children: ReactNode }) => { | ||
useEffect(() => { | ||
if (typeof window !== "undefined") { | ||
try { | ||
eruda.init(); | ||
} catch (error) { | ||
console.log("Eruda failed to initialize", error); | ||
} | ||
} | ||
}, []); | ||
|
||
return <>{props.children}</>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use client"; | ||
|
||
import { ReactNode } from "react"; | ||
import dynamic from "next/dynamic"; | ||
|
||
const Eruda = dynamic(() => import("./eruda-provider").then(c => c.Eruda), { | ||
ssr: false, | ||
}); | ||
|
||
export const ErudaProvider = (props: { children: ReactNode }) => { | ||
if (process.env.NEXT_PUBLIC_APP_ENV === "production") { | ||
return props.children; | ||
} | ||
return <Eruda>{props.children}</Eruda>; | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters