Created
July 13, 2022 14:57
-
-
Save polluterofminds/29588108fa4643aa9464478aeb95af3e to your computer and use it in GitHub Desktop.
Generating an Access Token With Submarine SDK
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"; | |
import { Submarine } from "pinata-submarine"; | |
const submarine = new Submarine(process.env.SUBMARINE_KEY, process.env.GATEWAY_URL); | |
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 timeInSeconds = 1000; | |
const link = await submarine.generateAccessLink(timeInSeconds, id, cid); | |
res.send(link); | |
} 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