This file contains hidden or 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 { getToken } from "next-auth/jwt" | |
import { NextResponse } from "next/server" | |
export async function middleware(req) { | |
// return early if url isn't supposed to be protected | |
if (!req.url.includes("/protected-url")) { | |
return NextResponse.next() | |
} | |
const session = await getToken({ req, secret: process.env.SECRET }) |
This file contains hidden or 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
export default function GQLClient(params) { | |
return { | |
async request(query, variables) { | |
const token = params.token ?? (await getToken(params.client)) | |
const res = await fetch(params.url, { | |
headers: { | |
"Content-Type": "application/json", | |
...(token ? { Authorization: `Bearer ${token}` } : undefined), | |
}, | |
method: "POST", |
This file contains hidden or 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 { NextApiRequest, NextApiResponse } from "next" | |
import log, { LogLevel } from "utils/server-logger" | |
import StackTraceGPS from "stacktrace-gps" | |
import ErrorStackParser from "error-stack-parser" | |
import fs from "fs" | |
import path from "path" | |
export default async function logger( | |
req: NextApiRequest, | |
res: NextApiResponse |
This file contains hidden or 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
az aks get-credentials --resource-group k8s-demo-ss --name k8s-demo-cluster-ss --file kubeconfig-ss |
This file contains hidden or 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 from "next-auth" | |
import Providers from "next-auth/providers" | |
import { addSeconds } from "date-fns" | |
import type { User } from "hooks/useUser" | |
import log from "utils/server-logger" | |
import sessionsDB, { InactiveSessionReason } from "lib/session-db" | |
import jwtDecode from "jwt-decode" | |
/** @see https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens#payload-claims */ | |
export interface IDToken { |
This file contains hidden or 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 NodeCache from "node-cache" | |
const cache = new NodeCache() | |
/** | |
* Retrieves an access_token from an OAuth Provider for building purposes, | |
* using client_credentials (client secret) authorization type. | |
*/ | |
export default async function getBuildToken(){ | |
try { |
This file contains hidden or 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 "fs" | |
import path from "path" | |
import chalk from "chalk" | |
const getDirectories = (source ) => { | |
const dirents = fs.readdirSync(source, { withFileTypes: true }) | |
return dirents | |
.filter( | |
(dirent) => |
This file contains hidden or 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
// I wish this file to be generated from my *.gql files | |
declare module '*/queries.gql' { | |
export const Something: string; | |
export const SomethingElse: string; | |
} |
This file contains hidden or 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
function profile(profile) { | |
return ({ | |
...profile, | |
id: profile.sub, | |
name: profile["http://domain.com/Events/Customer/Fullname"] ?? profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"], | |
verified: profile["email_verified"] === "True", | |
}) | |
} |
This file contains hidden or 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 * as React from "react" | |
/** Scrolls to an element after that element is added to the DOM */ | |
const useEventualScroll = ( | |
/** | |
* Holds the element to scroll to. | |
* The closer it is to that element, the less Mutations are observed | |
* by MutationObserver. If not defined, document will be used. | |
*/ | |
container?: null | HTMLElement |