Skip to content

Instantly share code, notes, and snippets.

@polluterofminds
Created July 13, 2022 14:57
Show Gist options
  • Save polluterofminds/29588108fa4643aa9464478aeb95af3e to your computer and use it in GitHub Desktop.
Save polluterofminds/29588108fa4643aa9464478aeb95af3e to your computer and use it in GitHub Desktop.
Generating an Access Token With Submarine SDK
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