Skip to content

Instantly share code, notes, and snippets.

View balazsorban44's full-sized avatar
🌍
Coding from anywhere

Balázs Orbán balazsorban44

🌍
Coding from anywhere
View GitHub Profile
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>;
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`
// 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,
}),
@balazsorban44
balazsorban44 / api.ts
Last active December 15, 2022 16:12
Auth.js Example
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: "",
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,
}),
],
// 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>
}
//...
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 },
@balazsorban44
balazsorban44 / index.html
Created March 4, 2022 02:03
Firefox bug: Image natural sizes reported incorrectly after the decode method has finished
<!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() {
@balazsorban44
balazsorban44 / apple-gen-secret.mjs
Last active November 21, 2024 13:25
Script to generate Apple Client secret
// 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")) {
const colors = {
primary: "bg-primary",
secondary: "bg-secondary"
} // 🥴 I don't want this...
export function Button(
props: {variant: "primary" | "secondary"}
) {
const { variant, ...rest } = props
return (