A Next.js project to serve a password-protected download link.
MIT License
This repo contains the basic Next.js project that will allow you to create a public password-protected file download link. The file will be protected using basic authentication.
Btw, support this repo in Product Hunt, will you? 😁
I needed a solution to make a file publicly downloadable, but
I couldn't find anything that meets those requirements. So I made this repo by storing the files in private GitHub repository and serving them through Vercel, both of which are FREE.
admin
and supersecret
as User and Password, respectively.You can also directly download the file from the browser by opening this link https://nextsecure.nico.fyi/api/download/secret.json. Enter admin
and supersecret
as User and Password, respectively.
And since the file is protected using basic authentication, you can also download the file directly from command line using curl:
curl -OJ "https://admin:[email protected]/api/download/secret.json"
ADMIN_USERNAME
and ADMIN_PASSWORD
environment variables with the username and password you want to use to protect your file.files
directory.https://your-vercel-deployment-url/api/download/the-file-name-here
URL.If you'd rather watch a video on how to use this project, check it out in this blog post.
The not-so-secret sauce is inside the app/api/download/[file_name]/route.ts
and middleware.ts
. In middleware.ts
, the app will check the credentials. In app/api/download/[file_name]/route.ts
, the app will find and return the file. That's it.
ADMIN_USERNAME
and ADMIN_PASSWORD
environment variables, or else the files can be freely downloaded.MIT
I'm making a book about Pull Requests Best Practices. Boost Your Team's Efficiency: Master the Art of Writing & Reviewing Pull Requests! . Check it out!