This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'node:fs'; | |
import path from 'node:path'; | |
import { renderToStaticMarkup } from 'react-dom/server'; | |
import { convert, type HtmlToTextOptions } from 'html-to-text'; | |
const emailFiles = fs.readdirSync(path.resolve(__dirname, '../src/emails')); | |
interface EmailTemplateConfig { | |
default: React.ReactElement; | |
props: Record<string, string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { withAuth } from "next-auth/middleware"; | |
export default withAuth( | |
function middleware(request) { | |
if (request.nextUrl.pathname !== "/") return; | |
return Response.redirect(new URL("/home", request.url)); | |
}, | |
// This is NextAuth.js | |
// Docs: https://next-auth.js.org/configuration/nextjs#pages | |
// Needs to be the same as your `authOptions.pages` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/api/auth/[...nextauth]/route.ts | |
import NextAuth, { type NextAuthOptions } from "next-auth" | |
import GitHub from "next-auth/providers/github" | |
export const authOptions: NextAuthOptions = { | |
providers: [ | |
GitHub({ | |
clientId: process.env.GITHUB_ID, | |
clientSecret: process.env.GITHUB_SECRET, | |
}), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AuthHandler } from "@auth/core" | |
// You get this from somewhere | |
const req = new Request("https://a.com/api/auth/session") | |
const res = await AuthHandler(req, { | |
// Make sure you trust the host header | |
trustHost: true, | |
// Eg.: `openssl rand -hex 32` | |
secret: "", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import NextAuth, { NextAuthOptions } from "next-auth" | |
import GithubProvider from "next-auth/providers/github" | |
export const authOptions: NextAuthOptions = { | |
providers: [ | |
GithubProvider({ | |
clientId: process.env.GITHUB_ID, | |
clientSecret: process.env.GITHUB_SECRET, | |
}), | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/page.jsx | |
import { unstable_getServerSession } from "next-auth/next" | |
export default async function Page() { | |
const session = await unstable_getServerSession() | |
return <pre>{JSON.stringify(session, null, 2)}</pre> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
providers: [ | |
Twitch({ | |
clientId: process.env.TWITCH_ID, | |
clientSecret: process.env.TWITCH_SECRET, | |
authorization: { params: { scope: "openid user:read:email moderation:read" } }, | |
async profile(profile, tokens) { | |
const id = profile.sub | |
const res = await fetch(`https://api.twitch.tv/helix/users?id=${id}}`, { | |
headers: { Authorization: `Bearer ${tokens.access_token}`, "Client-Id": process.env.TWITCH_ID }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Image width/height after decode</title> | |
<script> | |
window.onload = function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is now built into `npx auth add apple`! :tada: | |
// https://github.com/nextauthjs/cli/pull/10 | |
#!/bin/node | |
import { SignJWT } from "jose" | |
import { createPrivateKey } from "crypto" | |
if (process.argv.includes("--help") || process.argv.includes("-h")) { |
NewerOlder