├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md ├── biome.json ├── components.json ├── next.config.ts ├── package-lock.json ├── package.json ├── postcss.config.mjs ├── public ├── favicon.ico └── og-image.png ├── src ├── actions │ ├── auth.ts │ └── redirectToSnippet.ts ├── app │ ├── (auth) │ │ ├── layout.tsx │ │ ├── login │ │ │ └── page.tsx │ │ └── register │ │ │ └── page.tsx │ ├── (site) │ │ ├── [nevent] │ │ │ └── page.tsx │ │ ├── archive │ │ │ └── page.tsx │ │ ├── layout.tsx │ │ └── page.tsx │ ├── api │ │ └── auth │ │ │ └── [...nextauth] │ │ │ └── route.ts │ └── layout.tsx ├── auth │ └── index.ts ├── components │ └── ui │ │ ├── avatar.tsx │ │ ├── button.tsx │ │ ├── card.tsx │ │ ├── checkbox.tsx │ │ ├── dialog.tsx │ │ ├── dropdown-menu.tsx │ │ ├── form.tsx │ │ ├── input.tsx │ │ ├── label.tsx │ │ ├── mode-toggle.tsx │ │ ├── popover.tsx │ │ ├── scroll-area.tsx │ │ ├── select.tsx │ │ ├── separator.tsx │ │ ├── skeleton.tsx │ │ ├── sonner.tsx │ │ └── tooltip.tsx ├── features │ ├── editor │ │ ├── components │ │ │ ├── ActiveEditor.tsx │ │ │ ├── CopyButton.tsx │ │ │ ├── Description.tsx │ │ │ ├── DescriptionInput.tsx │ │ │ ├── Filename.tsx │ │ │ ├── FilenameInput.tsx │ │ │ ├── InputTagList.tsx │ │ │ ├── LanguageSelect.tsx │ │ │ ├── ReadEditor.tsx │ │ │ ├── TagList.tsx │ │ │ └── TagsInput.tsx │ │ ├── hooks │ │ │ └── useSnippetEvent.ts │ │ └── index.ts │ ├── login │ │ ├── components │ │ │ ├── Login.tsx │ │ │ └── UserDropdown.tsx │ │ └── index.ts │ ├── navigation │ │ ├── components │ │ │ ├── ArchiveNavButton.tsx │ │ │ └── CreateNavButton.tsx │ │ └── index.ts │ ├── post │ │ ├── components │ │ │ └── PostButton.tsx │ │ ├── hooks │ │ │ └── usePostMutation.ts │ │ └── index.ts │ ├── snippet-feed │ │ ├── components │ │ │ ├── SnippetCard.tsx │ │ │ ├── SnippetCardSkeleton.tsx │ │ │ └── SnippetFeed.tsx │ │ └── index.ts │ └── zap │ │ ├── components │ │ ├── ZapButton.tsx │ │ └── ZapDialog.tsx │ │ ├── index.ts │ │ └── lib │ │ └── zap.ts ├── hooks │ ├── useNostrProfile.ts │ ├── useNostrRelayMetaData.ts │ └── useNostrSnippets.ts ├── lib │ ├── constants.ts │ ├── languages.ts │ ├── nostr │ │ ├── createNevent.ts │ │ ├── createNostrProfile.ts │ │ ├── createNostrRelayMetadata.ts │ │ ├── createNostrSnippet.ts │ │ ├── finishEvent.ts │ │ ├── getTagValue.ts │ │ ├── parseUint8Array.ts │ │ ├── publish.ts │ │ └── shortNpub.ts │ └── utils.ts ├── providers │ ├── auth-provider.tsx │ ├── query-client-provider.tsx │ └── theme-provider.tsx ├── store │ └── index.ts ├── styles │ └── globals.css └── types │ └── index.ts ├── tsconfig.json └── types.d.ts /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: christianchiarulli 4 | patreon: chrisatmachine 5 | ko_fi: chrisatmachine 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.* 7 | .yarn/* 8 | !.yarn/patches 9 | !.yarn/plugins 10 | !.yarn/releases 11 | !.yarn/versions 12 | 13 | # testing 14 | /coverage 15 | 16 | # next.js 17 | /.next/ 18 | /out/ 19 | 20 | # production 21 | /build 22 | 23 | # misc 24 | .DS_Store 25 | *.pem 26 | 27 | # debug 28 | npm-debug.log* 29 | yarn-debug.log* 30 | yarn-error.log* 31 | .pnpm-debug.log* 32 | 33 | # env files (can opt-in for committing if needed) 34 | .env* 35 | 36 | # vercel 37 | .vercel 38 | 39 | # typescript 40 | *.tsbuildinfo 41 | next-env.d.ts 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 NODE-TEC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ✂️ Notebin 2 | 3 | Notebin is a code snippet sharing site similar to pastebin or GitHub gists. 4 | 5 | ## NIP-C0 6 | 7 | This is a simple reference implementation for [NIP-C0](https://github.com/nostr-protocol/nips/blob/master/C0.md). 8 | 9 | ## Developers 10 | 11 | - install dependencies 12 | 13 | ```shell 14 | npm i 15 | ``` 16 | 17 | - run the app 18 | 19 | ```shell 20 | npm run dev 21 | ``` 22 | -------------------------------------------------------------------------------- /biome.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", 3 | "vcs": { 4 | "enabled": true, 5 | "clientKind": "git", 6 | "useIgnoreFile": true 7 | }, 8 | "files": { "ignoreUnknown": false, "ignore": [] }, 9 | "formatter": { "enabled": true, "indentStyle": "space" }, 10 | "organizeImports": { "enabled": true }, 11 | "linter": { 12 | "enabled": true, 13 | "rules": { 14 | "suspicious": { 15 | "noArrayIndexKey": "off" 16 | }, 17 | "correctness": { 18 | "noUnusedImports": "warn", 19 | "useHookAtTopLevel": "error" 20 | }, 21 | "nursery": { 22 | "useSortedClasses": { 23 | "level": "warn", 24 | "fix": "safe", 25 | "options": { 26 | "functions": ["clsx", "cva", "cn"] 27 | } 28 | } 29 | }, 30 | "recommended": true 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "new-york", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "", 8 | "css": "src/app/styles/globals.css", 9 | "baseColor": "zinc", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "~/components", 15 | "utils": "~/lib/utils", 16 | "ui": "~/components/ui", 17 | "lib": "~/lib", 18 | "hooks": "~/hooks" 19 | }, 20 | "iconLibrary": "lucide" 21 | } -------------------------------------------------------------------------------- /next.config.ts: -------------------------------------------------------------------------------- 1 | import type { NextConfig } from "next"; 2 | 3 | const nextConfig: NextConfig = { 4 | images: { 5 | dangerouslyAllowSVG: true, 6 | remotePatterns: [ 7 | { 8 | protocol: "https", 9 | hostname: "**", 10 | }, 11 | ], 12 | }, 13 | }; 14 | 15 | export default nextConfig; 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "notebin", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev --turbopack", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@dicebear/collection": "^9.2.2", 13 | "@dicebear/core": "^9.2.2", 14 | "@hookform/resolvers": "^4.1.3", 15 | "@radix-ui/react-avatar": "^1.1.3", 16 | "@radix-ui/react-checkbox": "^1.1.4", 17 | "@radix-ui/react-dialog": "^1.1.6", 18 | "@radix-ui/react-dropdown-menu": "^2.1.6", 19 | "@radix-ui/react-label": "^2.1.2", 20 | "@radix-ui/react-popover": "^1.1.6", 21 | "@radix-ui/react-scroll-area": "^1.2.3", 22 | "@radix-ui/react-select": "^2.1.6", 23 | "@radix-ui/react-separator": "^1.1.2", 24 | "@radix-ui/react-slot": "^1.1.2", 25 | "@radix-ui/react-tooltip": "^1.1.8", 26 | "@tanstack/react-query": "^5.69.0", 27 | "@tanstack/react-query-devtools": "^5.69.0", 28 | "@uiw/codemirror-extensions-langs": "^4.23.10", 29 | "@uiw/codemirror-theme-github": "^4.23.10", 30 | "@uiw/react-codemirror": "^4.23.10", 31 | "class-variance-authority": "^0.7.1", 32 | "clsx": "^2.1.1", 33 | "lucide-react": "^0.484.0", 34 | "nanoid": "^5.1.5", 35 | "next": "15.2.4", 36 | "next-auth": "^4.24.11", 37 | "next-themes": "^0.4.6", 38 | "nostr-tools": "^2.11.0", 39 | "react": "^19.0.0", 40 | "react-codemirror-runmode": "^2.0.2", 41 | "react-dom": "^19.0.0", 42 | "react-hook-form": "^7.54.2", 43 | "sonner": "^2.0.2", 44 | "tailwind-merge": "^3.0.2", 45 | "tw-animate-css": "^1.2.4", 46 | "zod": "^3.24.2", 47 | "zustand": "^5.0.3" 48 | }, 49 | "devDependencies": { 50 | "@biomejs/biome": "1.9.4", 51 | "@tailwindcss/postcss": "^4.0.17", 52 | "@types/node": "^20.17.28", 53 | "@types/react": "^19.0.12", 54 | "@types/react-dom": "^19.0.4", 55 | "tailwindcss": "^4.0.17", 56 | "typescript": "^5.8.2" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /postcss.config.mjs: -------------------------------------------------------------------------------- 1 | const config = { 2 | plugins: ["@tailwindcss/postcss"], 3 | }; 4 | 5 | export default config; 6 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nodetec/notebin/68e5701255da6ae73d7d14be6f6d08da41ebb9c8/public/favicon.ico -------------------------------------------------------------------------------- /public/og-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nodetec/notebin/68e5701255da6ae73d7d14be6f6d08da41ebb9c8/public/og-image.png -------------------------------------------------------------------------------- /src/actions/auth.ts: -------------------------------------------------------------------------------- 1 | "use server"; 2 | 3 | import { authOptions } from "~/auth"; 4 | import type { UserWithKeys } from "~/types"; 5 | import { getServerSession } from "next-auth"; 6 | import { redirect } from "next/navigation"; 7 | 8 | export async function getUser() { 9 | const session = await getServerSession(authOptions); 10 | const user = session?.user as UserWithKeys | undefined; 11 | return user; 12 | } 13 | 14 | export async function redirectIfNotLoggedIn() { 15 | const session = await getServerSession(authOptions); 16 | const user = session?.user as UserWithKeys | undefined; 17 | if (!user) { 18 | redirect("/login"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/actions/redirectToSnippet.ts: -------------------------------------------------------------------------------- 1 | "use server"; 2 | 3 | import { redirect } from "next/navigation"; 4 | 5 | export async function redirectToSnippet(eventId: string) { 6 | redirect(`/${eventId}`); 7 | } 8 | -------------------------------------------------------------------------------- /src/app/(auth)/layout.tsx: -------------------------------------------------------------------------------- 1 | export default function RootLayout({ 2 | children, 3 | }: { 4 | children: React.ReactNode; 5 | }) { 6 | return ( 7 |
8 |
9 |
10 | {children} 11 |
12 |
13 |
14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /src/app/(auth)/login/page.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { useState } from "react"; 4 | 5 | import { zodResolver } from "@hookform/resolvers/zod"; 6 | import { bytesToHex } from "@noble/hashes/utils"; 7 | import { Button } from "~/components/ui/button"; 8 | import { 9 | Form, 10 | FormControl, 11 | FormField, 12 | FormItem, 13 | FormMessage, 14 | } from "~/components/ui/form"; 15 | import { Input } from "~/components/ui/input"; 16 | import { signIn } from "next-auth/react"; 17 | import Link from "next/link"; 18 | import { getPublicKey, nip19 } from "nostr-tools"; 19 | import { useForm } from "react-hook-form"; 20 | import * as z from "zod"; 21 | 22 | const isValidNsec = (nsec: string) => { 23 | try { 24 | return nip19.decode(nsec).type === "nsec"; 25 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 26 | } catch (e) { 27 | return false; 28 | } 29 | }; 30 | 31 | const formSchema = z.object({ 32 | nsec: z.string().refine(isValidNsec, { 33 | message: "Invalid nsec.", 34 | }), 35 | }); 36 | 37 | export default function UserAuthForm() { 38 | const [isLoading, setIsLoading] = useState(false); 39 | 40 | const form = useForm>({ 41 | resolver: zodResolver(formSchema), 42 | defaultValues: { 43 | nsec: "", 44 | }, 45 | }); 46 | 47 | const signInWithExtension = async ( 48 | e: React.MouseEvent 49 | ) => { 50 | e.preventDefault(); 51 | setIsLoading(true); 52 | if (typeof nostr !== "undefined") { 53 | const publicKey: string = await nostr.getPublicKey(); 54 | await signIn("credentials", { 55 | publicKey: publicKey, 56 | secretKey: 0, 57 | redirect: true, 58 | callbackUrl: "/", 59 | }); 60 | } else { 61 | alert("No extension found"); 62 | } 63 | }; 64 | 65 | async function onSubmit(values: z.infer) { 66 | setIsLoading(true); 67 | const { nsec } = values; 68 | const secretKeyUint8 = nip19.decode(nsec).data as Uint8Array; 69 | const publicKey = getPublicKey(secretKeyUint8); 70 | const secretKey = bytesToHex(secretKeyUint8); 71 | 72 | await signIn("credentials", { 73 | publicKey, 74 | secretKey, 75 | redirect: true, 76 | callbackUrl: "/", 77 | }); 78 | } 79 | 80 | return ( 81 |
82 |
83 |

Log in

84 |

85 | New to Nostr?{" "} 86 | 90 | Create an account 91 | 92 |

93 |
94 | 95 |
96 | 100 | ( 104 | 105 | 106 | 112 | 113 | 114 | 115 | )} 116 | /> 117 | 120 | 121 | 122 |
123 |
124 | 125 |
126 |
127 | 128 | Or continue with 129 | 130 |
131 |
132 | 150 |
151 | ); 152 | } 153 | -------------------------------------------------------------------------------- /src/app/(auth)/register/page.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { useEffect, useState } from "react"; 4 | 5 | import { zodResolver } from "@hookform/resolvers/zod"; 6 | import { Button } from "~/components/ui/button"; 7 | import { 8 | Form, 9 | FormControl, 10 | FormField, 11 | FormItem, 12 | FormMessage, 13 | } from "~/components/ui/form"; 14 | import { Input } from "~/components/ui/input"; 15 | import { signIn } from "next-auth/react"; 16 | import Link from "next/link"; 17 | import { generateSecretKey, getPublicKey, nip19 } from "nostr-tools"; 18 | import { useForm } from "react-hook-form"; 19 | import * as z from "zod"; 20 | 21 | const isValidNpub = (npub: string) => { 22 | try { 23 | return nip19.decode(npub).type === "npub"; 24 | } catch (e) { 25 | return false; 26 | } 27 | }; 28 | 29 | const isValidNsec = (nsec: string) => { 30 | try { 31 | return nip19.decode(nsec).type === "nsec"; 32 | } catch (e) { 33 | return false; 34 | } 35 | }; 36 | 37 | const formSchema = z.object({ 38 | npub: z.string().refine(isValidNpub, { 39 | message: "Invalid npub.", 40 | }), 41 | nsec: z.string().refine(isValidNsec, { 42 | message: "Invalid nsec.", 43 | }), 44 | }); 45 | 46 | export default function RegisterForm() { 47 | const [isLoading, setIsLoading] = useState(false); 48 | 49 | const form = useForm>({ 50 | resolver: zodResolver(formSchema), 51 | defaultValues: { 52 | nsec: "", 53 | npub: "", 54 | }, 55 | }); 56 | 57 | const { reset } = form; 58 | 59 | useEffect(() => { 60 | const secretKey = generateSecretKey(); 61 | const publicKey = getPublicKey(secretKey); 62 | const nsec = nip19.nsecEncode(secretKey); 63 | const npub = nip19.npubEncode(publicKey); 64 | 65 | reset({ 66 | nsec, 67 | npub, 68 | }); 69 | }, [reset]); 70 | 71 | async function onSubmit(values: z.infer) { 72 | setIsLoading(true); 73 | const { npub, nsec } = values; 74 | const publicKey = nip19.decode(npub).data as string; 75 | const secretKey = nip19.decode(nsec).data as Uint8Array; 76 | 77 | await signIn("credentials", { 78 | publicKey, 79 | secretKey, 80 | redirect: true, 81 | callbackUrl: "/", 82 | }); 83 | } 84 | 85 | return ( 86 |
87 |
88 |

89 | Create an Account 90 |

91 |

92 | Already have an account?{" "} 93 | 97 | Sign in 98 | 99 |

100 |
101 | 102 |
103 | 107 | ( 111 | 112 | 113 | 119 | 120 | 121 | 122 | )} 123 | /> 124 | ( 128 | 129 | 130 | 136 | 137 | 138 | 139 | )} 140 | /> 141 | 142 |

143 | Use a 144 | 145 | 151 | nostr extension 152 | 153 | 154 | to login in the future 155 |

156 | 157 | 160 | 161 | 162 |
163 | ); 164 | } 165 | -------------------------------------------------------------------------------- /src/app/(site)/[nevent]/page.tsx: -------------------------------------------------------------------------------- 1 | import { getServerSession } from "next-auth"; 2 | import { nip19 } from "nostr-tools"; 3 | import { authOptions } from "~/auth"; 4 | import { Description, Filename, CopyButton } from "~/features/editor"; 5 | import { ReadEditor } from "~/features/editor"; 6 | import { TagList } from "~/features/editor/components/TagList"; 7 | import { ZapButton } from "~/features/zap"; 8 | import type { UserWithKeys } from "~/types"; 9 | 10 | export default async function SnippetPage({ 11 | params, 12 | }: { 13 | params: Promise<{ nevent: string }>; 14 | }) { 15 | const { nevent } = await params; 16 | 17 | // Normalize the nevent string to lowercase before decoding 18 | const normalizedNevent = nevent.toLowerCase(); 19 | const decodeResult = nip19.decode(normalizedNevent); 20 | 21 | const session = await getServerSession(authOptions); 22 | 23 | const user = session?.user as UserWithKeys; 24 | 25 | if (decodeResult.type === "nevent") { 26 | const { kind, id, author, relays } = decodeResult.data; 27 | 28 | // TODO: refactor this nonsense 29 | return ( 30 | <> 31 | 32 |
33 |
34 | 40 |
41 | 47 | {user?.publicKey && author && ( 48 | 53 | )} 54 |
55 |
56 | 62 |
63 | 64 | 65 | ); 66 | } 67 | 68 | return
Invalid Nevent
; 69 | } 70 | -------------------------------------------------------------------------------- /src/app/(site)/archive/page.tsx: -------------------------------------------------------------------------------- 1 | import { SnippetFeed } from "~/features/snippet-feed"; 2 | 3 | export default function ArchivePage() { 4 | return ; 5 | } 6 | -------------------------------------------------------------------------------- /src/app/(site)/layout.tsx: -------------------------------------------------------------------------------- 1 | import { Login } from "~/features/login/components/Login"; 2 | import { shortenNpub } from "~/lib/nostr/shortNpub"; 3 | import type { UserWithKeys } from "~/types"; 4 | import { getServerSession } from "next-auth"; 5 | import { authOptions } from "~/auth"; 6 | import Link from "next/link"; 7 | import { UserDropdown } from "~/features/login"; 8 | import { CreateNavButton } from "~/features/navigation/components/CreateNavButton"; 9 | import { ArchiveNavButton } from "~/features/navigation/components/ArchiveNavButton"; 10 | 11 | export default async function SiteLayout({ 12 | children, 13 | }: { 14 | children: React.ReactNode; 15 | }) { 16 | const session = await getServerSession(authOptions); 17 | 18 | const user = session?.user as UserWithKeys; 19 | 20 | const shortNpub = shortenNpub(user?.publicKey); 21 | 22 | return ( 23 |
24 |
25 |
26 |
27 | 28 |

29 | Notebin.io 30 |

31 | 32 | 33 | {/* */} 34 |
35 |
36 | 37 | 38 | {user?.publicKey ? ( 39 | 40 | ) : ( 41 | {shortNpub ?? "Login"} 42 | )} 43 |
44 |
45 | {children} 46 |
47 |
48 | ); 49 | } 50 | -------------------------------------------------------------------------------- /src/app/(site)/page.tsx: -------------------------------------------------------------------------------- 1 | import { FilenameInput, LanguageSelect } from "~/features/editor"; 2 | import { DescriptionInput } from "~/features/editor"; 3 | import { getServerSession } from "next-auth"; 4 | import { authOptions } from "~/auth"; 5 | import type { UserWithKeys } from "~/types"; 6 | import { PostButton } from "~/features/post"; 7 | import { ActiveEditor } from "~/features/editor"; 8 | import { TagsInput } from "~/features/editor"; 9 | import { InputTagList } from "~/features/editor"; 10 | 11 | export default async function HomePage() { 12 | const session = await getServerSession(authOptions); 13 | 14 | const user = session?.user as UserWithKeys; 15 | 16 | return ( 17 | <> 18 | 19 |
20 |
21 | 22 | 23 |
24 | 25 | 26 |
27 | 28 |
29 | {user?.publicKey && ( 30 | 31 | )} 32 |
33 | 34 | ); 35 | } 36 | -------------------------------------------------------------------------------- /src/app/api/auth/[...nextauth]/route.ts: -------------------------------------------------------------------------------- 1 | import NextAuth from "next-auth"; 2 | import { authOptions } from "~/auth"; 3 | 4 | const handler = NextAuth(authOptions); 5 | 6 | export { handler as GET, handler as POST }; 7 | -------------------------------------------------------------------------------- /src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import type { Metadata } from "next"; 2 | import { Geist, Geist_Mono } from "next/font/google"; 3 | import "~/styles/globals.css"; 4 | import { ThemeProvider } from "~/providers/theme-provider"; 5 | import AuthProvider from "~/providers/auth-provider"; 6 | import QueryClientProviderWrapper from "~/providers/query-client-provider"; 7 | import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; 8 | 9 | import { Toaster } from "sonner"; 10 | import { TooltipProvider } from "~/components/ui/tooltip"; 11 | 12 | const geistSans = Geist({ 13 | variable: "--font-geist-sans", 14 | subsets: ["latin"], 15 | }); 16 | 17 | const geistMono = Geist_Mono({ 18 | variable: "--font-geist-mono", 19 | subsets: ["latin"], 20 | }); 21 | 22 | export const metadata: Metadata = { 23 | title: "Notebin.io | Code Sharing Platform", 24 | description: 25 | "A modern, fast, and secure platform for developers to share code snippets.", 26 | keywords: [ 27 | "code sharing", 28 | "code snippets", 29 | "developer tools", 30 | "collaboration", 31 | "programming", 32 | "code review", 33 | ], 34 | authors: [{ name: "Notebin.io" }], 35 | creator: "Notebin.io", 36 | publisher: "Notebin.io", 37 | robots: "index, follow", 38 | metadataBase: new URL("https://notebin.io"), 39 | openGraph: { 40 | type: "website", 41 | locale: "en_US", 42 | url: "https://notebin.io", 43 | title: "Notebin.io - Modern Code Sharing Platform", 44 | description: 45 | "Share and collaborate on code snippets easily with Notebin.io. A modern, fast, and secure platform for developers.", 46 | siteName: "Notebin.io", 47 | images: [ 48 | { 49 | url: "/og-image.png", 50 | width: 1200, 51 | height: 630, 52 | alt: "Notebin.io - Code Sharing Platform", 53 | }, 54 | ], 55 | }, 56 | twitter: { 57 | card: "summary_large_image", 58 | title: "Notebin.io - Modern Code Sharing Platform", 59 | description: 60 | "Share and collaborate on code snippets easily with Notebin.io", 61 | images: ["/og-image.png"], 62 | creator: "@notebinio", 63 | }, 64 | viewport: { 65 | width: "device-width", 66 | initialScale: 1, 67 | maximumScale: 1, 68 | }, 69 | }; 70 | 71 | export default function RootLayout({ 72 | children, 73 | }: Readonly<{ 74 | children: React.ReactNode; 75 | }>) { 76 | return ( 77 | 78 | 81 | 87 | 88 | 89 | 90 | {children} 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | ); 100 | } 101 | -------------------------------------------------------------------------------- /src/auth/index.ts: -------------------------------------------------------------------------------- 1 | import type { TokenWithKeys, UserWithKeys } from "~/types"; 2 | import type { AuthOptions } from "next-auth"; 3 | import CredentialsProvider from "next-auth/providers/credentials"; 4 | 5 | export const authOptions: AuthOptions = { 6 | providers: [ 7 | CredentialsProvider({ 8 | name: "nostr", 9 | credentials: { 10 | publicKey: { 11 | label: "Public Key", 12 | type: "text", 13 | placeholder: "npub...", 14 | }, 15 | secretKey: { 16 | label: "Secret Key", 17 | type: "text", 18 | placeholder: "nsec...", 19 | }, 20 | }, 21 | async authorize(credentials, _) { 22 | // no credentials 23 | if (!credentials) return null; 24 | 25 | // no publicKey and no secretKey 26 | if (!credentials?.publicKey && !credentials.secretKey) { 27 | return null; 28 | } 29 | 30 | // publicKey and no secretKey 31 | if (credentials.publicKey && !credentials.secretKey) { 32 | const user = { 33 | id: credentials.publicKey, 34 | publicKey: credentials.publicKey, 35 | secretKey: "", 36 | }; 37 | return user; 38 | } 39 | 40 | // publicKey and secretKey 41 | if (credentials.publicKey && credentials.secretKey) { 42 | return { 43 | id: credentials.publicKey, 44 | publicKey: credentials.publicKey, 45 | secretKey: credentials.secretKey, 46 | }; 47 | } 48 | 49 | // no publicKey and secretKey 50 | return null; 51 | }, 52 | }), 53 | ], 54 | pages: { 55 | signIn: "/login", 56 | // signOut: "/signout", 57 | error: "/error", // Error code passed in query string as ?error= 58 | // verifyRequest: "/auth/verify-request", // (used for check email message) 59 | newUser: "/register", // New users will be directed here on first sign in (leave the property out if not of interest) 60 | }, 61 | session: { 62 | strategy: "jwt", 63 | }, 64 | callbacks: { 65 | async jwt({ token, user }) { 66 | // If the user object exists, it means this is the initial token creation. 67 | if (user) { 68 | token.publicKey = (user as UserWithKeys).publicKey; 69 | token.secretKey = (user as UserWithKeys).secretKey; 70 | } 71 | return token; 72 | }, 73 | 74 | async session({ session, token }) { 75 | // Extract the publicKey from the JWT token and add it to the session object 76 | const user = session.user as UserWithKeys; 77 | user.publicKey = (token as TokenWithKeys).publicKey; 78 | user.secretKey = (token as TokenWithKeys).secretKey; 79 | return session; 80 | }, 81 | }, 82 | debug: process.env.NODE_ENV === "development", 83 | }; 84 | -------------------------------------------------------------------------------- /src/components/ui/avatar.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as AvatarPrimitive from "@radix-ui/react-avatar" 5 | 6 | import { cn } from "~/lib/utils" 7 | 8 | function Avatar({ 9 | className, 10 | ...props 11 | }: React.ComponentProps) { 12 | return ( 13 | 21 | ) 22 | } 23 | 24 | function AvatarImage({ 25 | className, 26 | ...props 27 | }: React.ComponentProps) { 28 | return ( 29 | 34 | ) 35 | } 36 | 37 | function AvatarFallback({ 38 | className, 39 | ...props 40 | }: React.ComponentProps) { 41 | return ( 42 | 50 | ) 51 | } 52 | 53 | export { Avatar, AvatarImage, AvatarFallback } 54 | -------------------------------------------------------------------------------- /src/components/ui/button.tsx: -------------------------------------------------------------------------------- 1 | import type * as React from "react"; 2 | import { Slot } from "@radix-ui/react-slot"; 3 | import { cva, type VariantProps } from "class-variance-authority"; 4 | 5 | import { cn } from "~/lib/utils"; 6 | 7 | const buttonVariants = cva( 8 | "inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-md font-medium text-sm outline-none transition-all disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0", 9 | { 10 | variants: { 11 | variant: { 12 | default: 13 | "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90", 14 | destructive: 15 | "bg-destructive text-white shadow-xs hover:bg-destructive/90 dark:bg-destructive/60", 16 | outline: 17 | "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50", 18 | secondary: 19 | "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80", 20 | ghost: 21 | "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50", 22 | link: "text-primary underline-offset-4 hover:underline", 23 | }, 24 | size: { 25 | default: "h-9 px-4 py-2 has-[>svg]:px-3", 26 | sm: "h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5", 27 | lg: "h-10 rounded-md px-6 has-[>svg]:px-4", 28 | icon: "size-9", 29 | }, 30 | }, 31 | defaultVariants: { 32 | variant: "default", 33 | size: "default", 34 | }, 35 | }, 36 | ); 37 | 38 | function Button({ 39 | className, 40 | variant, 41 | size, 42 | asChild = false, 43 | ...props 44 | }: React.ComponentProps<"button"> & 45 | VariantProps & { 46 | asChild?: boolean; 47 | }) { 48 | const Comp = asChild ? Slot : "button"; 49 | 50 | return ( 51 | 56 | ); 57 | } 58 | 59 | export { Button, buttonVariants }; 60 | -------------------------------------------------------------------------------- /src/components/ui/card.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { cn } from "~/lib/utils" 4 | 5 | function Card({ className, ...props }: React.ComponentProps<"div">) { 6 | return ( 7 |
15 | ) 16 | } 17 | 18 | function CardHeader({ className, ...props }: React.ComponentProps<"div">) { 19 | return ( 20 |
28 | ) 29 | } 30 | 31 | function CardTitle({ className, ...props }: React.ComponentProps<"div">) { 32 | return ( 33 |
38 | ) 39 | } 40 | 41 | function CardDescription({ className, ...props }: React.ComponentProps<"div">) { 42 | return ( 43 |
48 | ) 49 | } 50 | 51 | function CardAction({ className, ...props }: React.ComponentProps<"div">) { 52 | return ( 53 |
61 | ) 62 | } 63 | 64 | function CardContent({ className, ...props }: React.ComponentProps<"div">) { 65 | return ( 66 |
71 | ) 72 | } 73 | 74 | function CardFooter({ className, ...props }: React.ComponentProps<"div">) { 75 | return ( 76 |
81 | ) 82 | } 83 | 84 | export { 85 | Card, 86 | CardHeader, 87 | CardFooter, 88 | CardTitle, 89 | CardAction, 90 | CardDescription, 91 | CardContent, 92 | } 93 | -------------------------------------------------------------------------------- /src/components/ui/checkbox.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as CheckboxPrimitive from "@radix-ui/react-checkbox" 5 | import { CheckIcon } from "lucide-react" 6 | 7 | import { cn } from "~/lib/utils" 8 | 9 | function Checkbox({ 10 | className, 11 | ...props 12 | }: React.ComponentProps) { 13 | return ( 14 | 22 | 26 | 27 | 28 | 29 | ) 30 | } 31 | 32 | export { Checkbox } 33 | -------------------------------------------------------------------------------- /src/components/ui/dialog.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as DialogPrimitive from "@radix-ui/react-dialog" 5 | import { XIcon } from "lucide-react" 6 | 7 | import { cn } from "~/lib/utils" 8 | 9 | function Dialog({ 10 | ...props 11 | }: React.ComponentProps) { 12 | return 13 | } 14 | 15 | function DialogTrigger({ 16 | ...props 17 | }: React.ComponentProps) { 18 | return 19 | } 20 | 21 | function DialogPortal({ 22 | ...props 23 | }: React.ComponentProps) { 24 | return 25 | } 26 | 27 | function DialogClose({ 28 | ...props 29 | }: React.ComponentProps) { 30 | return 31 | } 32 | 33 | function DialogOverlay({ 34 | className, 35 | ...props 36 | }: React.ComponentProps) { 37 | return ( 38 | 46 | ) 47 | } 48 | 49 | function DialogContent({ 50 | className, 51 | children, 52 | ...props 53 | }: React.ComponentProps) { 54 | return ( 55 | 56 | 57 | 65 | {children} 66 | 67 | 68 | Close 69 | 70 | 71 | 72 | ) 73 | } 74 | 75 | function DialogHeader({ className, ...props }: React.ComponentProps<"div">) { 76 | return ( 77 |
82 | ) 83 | } 84 | 85 | function DialogFooter({ className, ...props }: React.ComponentProps<"div">) { 86 | return ( 87 |
95 | ) 96 | } 97 | 98 | function DialogTitle({ 99 | className, 100 | ...props 101 | }: React.ComponentProps) { 102 | return ( 103 | 108 | ) 109 | } 110 | 111 | function DialogDescription({ 112 | className, 113 | ...props 114 | }: React.ComponentProps) { 115 | return ( 116 | 121 | ) 122 | } 123 | 124 | export { 125 | Dialog, 126 | DialogClose, 127 | DialogContent, 128 | DialogDescription, 129 | DialogFooter, 130 | DialogHeader, 131 | DialogOverlay, 132 | DialogPortal, 133 | DialogTitle, 134 | DialogTrigger, 135 | } 136 | -------------------------------------------------------------------------------- /src/components/ui/dropdown-menu.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu" 5 | import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react" 6 | 7 | import { cn } from "~/lib/utils" 8 | 9 | function DropdownMenu({ 10 | ...props 11 | }: React.ComponentProps) { 12 | return 13 | } 14 | 15 | function DropdownMenuPortal({ 16 | ...props 17 | }: React.ComponentProps) { 18 | return ( 19 | 20 | ) 21 | } 22 | 23 | function DropdownMenuTrigger({ 24 | ...props 25 | }: React.ComponentProps) { 26 | return ( 27 | 31 | ) 32 | } 33 | 34 | function DropdownMenuContent({ 35 | className, 36 | sideOffset = 4, 37 | ...props 38 | }: React.ComponentProps) { 39 | return ( 40 | 41 | 50 | 51 | ) 52 | } 53 | 54 | function DropdownMenuGroup({ 55 | ...props 56 | }: React.ComponentProps) { 57 | return ( 58 | 59 | ) 60 | } 61 | 62 | function DropdownMenuItem({ 63 | className, 64 | inset, 65 | variant = "default", 66 | ...props 67 | }: React.ComponentProps & { 68 | inset?: boolean 69 | variant?: "default" | "destructive" 70 | }) { 71 | return ( 72 | 82 | ) 83 | } 84 | 85 | function DropdownMenuCheckboxItem({ 86 | className, 87 | children, 88 | checked, 89 | ...props 90 | }: React.ComponentProps) { 91 | return ( 92 | 101 | 102 | 103 | 104 | 105 | 106 | {children} 107 | 108 | ) 109 | } 110 | 111 | function DropdownMenuRadioGroup({ 112 | ...props 113 | }: React.ComponentProps) { 114 | return ( 115 | 119 | ) 120 | } 121 | 122 | function DropdownMenuRadioItem({ 123 | className, 124 | children, 125 | ...props 126 | }: React.ComponentProps) { 127 | return ( 128 | 136 | 137 | 138 | 139 | 140 | 141 | {children} 142 | 143 | ) 144 | } 145 | 146 | function DropdownMenuLabel({ 147 | className, 148 | inset, 149 | ...props 150 | }: React.ComponentProps & { 151 | inset?: boolean 152 | }) { 153 | return ( 154 | 163 | ) 164 | } 165 | 166 | function DropdownMenuSeparator({ 167 | className, 168 | ...props 169 | }: React.ComponentProps) { 170 | return ( 171 | 176 | ) 177 | } 178 | 179 | function DropdownMenuShortcut({ 180 | className, 181 | ...props 182 | }: React.ComponentProps<"span">) { 183 | return ( 184 | 192 | ) 193 | } 194 | 195 | function DropdownMenuSub({ 196 | ...props 197 | }: React.ComponentProps) { 198 | return 199 | } 200 | 201 | function DropdownMenuSubTrigger({ 202 | className, 203 | inset, 204 | children, 205 | ...props 206 | }: React.ComponentProps & { 207 | inset?: boolean 208 | }) { 209 | return ( 210 | 219 | {children} 220 | 221 | 222 | ) 223 | } 224 | 225 | function DropdownMenuSubContent({ 226 | className, 227 | ...props 228 | }: React.ComponentProps) { 229 | return ( 230 | 238 | ) 239 | } 240 | 241 | export { 242 | DropdownMenu, 243 | DropdownMenuPortal, 244 | DropdownMenuTrigger, 245 | DropdownMenuContent, 246 | DropdownMenuGroup, 247 | DropdownMenuLabel, 248 | DropdownMenuItem, 249 | DropdownMenuCheckboxItem, 250 | DropdownMenuRadioGroup, 251 | DropdownMenuRadioItem, 252 | DropdownMenuSeparator, 253 | DropdownMenuShortcut, 254 | DropdownMenuSub, 255 | DropdownMenuSubTrigger, 256 | DropdownMenuSubContent, 257 | } 258 | -------------------------------------------------------------------------------- /src/components/ui/form.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as LabelPrimitive from "@radix-ui/react-label" 5 | import { Slot } from "@radix-ui/react-slot" 6 | import { 7 | Controller, 8 | FormProvider, 9 | useFormContext, 10 | useFormState, 11 | type ControllerProps, 12 | type FieldPath, 13 | type FieldValues, 14 | } from "react-hook-form" 15 | 16 | import { cn } from "~/lib/utils" 17 | import { Label } from "~/components/ui/label" 18 | 19 | const Form = FormProvider 20 | 21 | type FormFieldContextValue< 22 | TFieldValues extends FieldValues = FieldValues, 23 | TName extends FieldPath = FieldPath, 24 | > = { 25 | name: TName 26 | } 27 | 28 | const FormFieldContext = React.createContext( 29 | {} as FormFieldContextValue 30 | ) 31 | 32 | const FormField = < 33 | TFieldValues extends FieldValues = FieldValues, 34 | TName extends FieldPath = FieldPath, 35 | >({ 36 | ...props 37 | }: ControllerProps) => { 38 | return ( 39 | 40 | 41 | 42 | ) 43 | } 44 | 45 | const useFormField = () => { 46 | const fieldContext = React.useContext(FormFieldContext) 47 | const itemContext = React.useContext(FormItemContext) 48 | const { getFieldState } = useFormContext() 49 | const formState = useFormState({ name: fieldContext.name }) 50 | const fieldState = getFieldState(fieldContext.name, formState) 51 | 52 | if (!fieldContext) { 53 | throw new Error("useFormField should be used within ") 54 | } 55 | 56 | const { id } = itemContext 57 | 58 | return { 59 | id, 60 | name: fieldContext.name, 61 | formItemId: `${id}-form-item`, 62 | formDescriptionId: `${id}-form-item-description`, 63 | formMessageId: `${id}-form-item-message`, 64 | ...fieldState, 65 | } 66 | } 67 | 68 | type FormItemContextValue = { 69 | id: string 70 | } 71 | 72 | const FormItemContext = React.createContext( 73 | {} as FormItemContextValue 74 | ) 75 | 76 | function FormItem({ className, ...props }: React.ComponentProps<"div">) { 77 | const id = React.useId() 78 | 79 | return ( 80 | 81 |
86 | 87 | ) 88 | } 89 | 90 | function FormLabel({ 91 | className, 92 | ...props 93 | }: React.ComponentProps) { 94 | const { error, formItemId } = useFormField() 95 | 96 | return ( 97 |