Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Next.js + Lens Client integration example #1045

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions examples/nextjs-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
4 changes: 4 additions & 0 deletions examples/nextjs-client/.stackblitzrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"startCommand": "npm run dev",
"env": {}
}
5 changes: 5 additions & 0 deletions examples/nextjs-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Next.js - Lens Client Integration Example

This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/lens-protocol/lens-sdk/tree/next/examples/nextjs-client)
7 changes: 7 additions & 0 deletions examples/nextjs-client/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
/* config options here */
};

export default nextConfig;
24 changes: 24 additions & 0 deletions examples/nextjs-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "nextjs-client",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@lens-protocol/client": "canary",
"next": "15.1.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"simpledotcss": "^2.3.3"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"typescript": "^5"
}
}
5 changes: 5 additions & 0 deletions examples/nextjs-client/src/app/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PublicClient, testnet } from '@lens-protocol/client';

export const client = PublicClient.create({
environment: testnet,
});
Binary file added examples/nextjs-client/src/app/favicon.ico
Binary file not shown.
42 changes: 42 additions & 0 deletions examples/nextjs-client/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
:root {
--background: #ffffff;
--foreground: #171717;
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
}

body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

a {
color: inherit;
text-decoration: none;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
}
31 changes: 31 additions & 0 deletions examples/nextjs-client/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Metadata } from 'next';
import { Geist, Geist_Mono } from 'next/font/google';
import 'simpledotcss/simple.min.css';
import './globals.css';

const geistSans = Geist({
variable: '--font-geist-sans',
subsets: ['latin'],
});

const geistMono = Geist_Mono({
variable: '--font-geist-mono',
subsets: ['latin'],
});

export const metadata: Metadata = {
title: 'Next.js - Lens Client Integration',
description: 'Generated by create next app',
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang='en'>
<body className={`${geistSans.variable} ${geistMono.variable}`}>{children}</body>
</html>
);
}
26 changes: 26 additions & 0 deletions examples/nextjs-client/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AccountsOrderBy, PageSize } from '@lens-protocol/client';
import { fetchAccounts } from '@lens-protocol/client/actions';
import { client } from './client';

export default async function Home() {
const result = await fetchAccounts(client, {
orderBy: AccountsOrderBy.AccountScore,
pageSize: PageSize.Ten,
});

if (result.isErr()) {
return <div>{result.error.message}</div>;
}

return (
<div>
<p>Top 10 Accounts by Account Score:</p>

<ul>
{result.value?.items.map((account) => (
<li key={account.address}>{account.username?.value}</li>
))}
</ul>
</div>
);
}
27 changes: 27 additions & 0 deletions examples/nextjs-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Loading