Last active
April 8, 2022 19:07
-
-
Save polluterofminds/d4c7b934a7122f804b709107ced29e5b to your computer and use it in GitHub Desktop.
Members Only Step 11
This file contains hidden or 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
import { getSession } from "next-auth/react"; | |
const API_ENDPOINT = "https://managed.mypinata.cloud/api/v1"; | |
export default async function handler(req, res) { | |
try { | |
const session = await getSession({ req }); | |
if (!session) { | |
return res.status(401).send("Not signed in"); | |
} | |
const { id, cid } = req.query; | |
if (!id || !cid) { | |
return res.status(400).send("No ID or no CID provided"); | |
} | |
const body = { | |
timeoutSeconds: 3600, | |
contentIds: [id], | |
}; | |
const tokenRes = await fetch(`${API_ENDPOINT}/auth/content/jwt`, { | |
method: "POST", | |
headers: { | |
"x-api-key": process.env.SUBMARINE_KEY, | |
"content-type": "application/json" | |
}, | |
body: JSON.stringify(body), | |
}); | |
const token = await tokenRes.json(); | |
res.send(`${process.env.GATEWAY_URL}/ipfs/${cid}?accessToken=${token}`); | |
} catch (error) { | |
console.log(error); | |
res.status(500).send("Server error"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment