Skip to content

Latest commit

 

History

History

web

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

micro-stacks + next.js

This is an example Next.js application that implements @micro-stacks/react to add Stacks-based web3 authentication. The example also details how to share session state between client and server using [iron-session](https://github.com/vvo/iron-session.

This example is part of a guide found on micro-stacks.dev: Building a Stacks app with Next.js

Online demo: nextjs-example.micro-stacks.dev

Overview

In this example:

  • micro-stacks related dependencies are installed
  • Stacks auth is implemented
  • iron-session as a dependency
  • API routes for saving/destroying session
  • _app.tsx has the ClientProvider for micro-stacks context
  • Fetching the user session and passing it to ClientProvider

Getting Started

First, create a new .env.local file:

# ⚠️ The SECRET_COOKIE_PASSWORD should never be inside your repository directly, it's here only to ease
# the example deployment
# For local development, you should store it inside a `.env.local` gitignored file
# See https://nextjs.org/docs/basic-features/environment-variables#loading-environment-variables

SECRET_COOKIE_PASSWORD=2gyZ3GDw3LHZQKDhPmPDL3sjREVRXPr8

Then install your dependencies:

pnpm i
# or
yarn

Then run the dev task:

pnpm dev
# or
yarn dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying pages/index.tsx. The page auto-updates as you edit the file.

API routes can be accessed on http://localhost:3000/api/session/save or http://localhost:3000/api/session/destroy. These endpoint can be found in pages/api/session/save.ts and pages/api/session/destroy.ts.

The pages/api directory is mapped to /api/*. Files in this directory are treated as API routes instead of React pages.

Learn More

To learn more about micro-stacks:

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Community

stars downloads license

micro-stacks is created and maintained by Fungible Systems, a web3-focused design and engineering studio.

Follow @FungibleSystems on Twitter for updates and memes :~)

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.