Skip to content

Instantly share code, notes, and snippets.

View mauriciord's full-sized avatar

Maurício R Duarte mauriciord

View GitHub Profile
@mauriciord
mauriciord / _middleware.ts
Created January 24, 2024 17:08 — forked from f1729/_middleware.ts
Add password protection to any Vercel website, save $150/month.
import { addYears } from 'date-fns'
import { NextRequest, NextResponse } from 'next/server'
function middleware(req: NextRequest) {
if (req.nextUrl.pathname.startsWith('/api')) {
return NextResponse.next()
}
if (process.env.VERCEL_ENV !== 'preview') {
return NextResponse.next()
@mauriciord
mauriciord / [...nextauth].ts
Created October 2, 2023 18:31
Next Auth ignoring Next Auth env on proxy domains
export default async function auth(req: NextApiRequest, res: NextApiResponse) {
if (process.env.VERCEL) {
// prefer NEXTAUTH_URL, fallback to x-forwarded-host
req.headers['x-forwarded-host'] =
process.env.NEXTAUTH_URL ?? req.headers['x-forwarded-host']
}
return await NextAuth(req, res, authOptions())
}
diff --git a/node_modules/next-auth/next/index.js b/node_modules/next-auth/next/index.js
index b17feef..3e56332 100644
--- a/node_modules/next-auth/next/index.js
+++ b/node_modules/next-auth/next/index.js
@@ -58,11 +58,6 @@ async function NextAuthRouteHandler(req, context, options) {
(_options$secret2 = options.secret) !== null && _options$secret2 !== void 0 ? _options$secret2 : options.secret = process.env.NEXTAUTH_SECRET;
- const {
- headers,
@mauriciord
mauriciord / axios-https-agent.js
Created August 24, 2023 16:02
allow legacy server openSSl error
axios.defaults.httpsAgent = new https.Agent({
// for self signed you could also add
// rejectUnauthorized: false,
// allow legacy server
secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT,
})
@mauriciord
mauriciord / highest.js
Created September 6, 2022 13:18
Highest in a string
const s = 'abcergsserswsGiogjadSf48ewfu64896'
const listByKey = Array.from(s).reduce((acc, char) => {
if (!isNaN(char)) return acc
const letter = char.toLowerCase()
const count = acc[letter] ? acc[letter] + 1 : 1
return {
...acc,
@mauriciord
mauriciord / Snackbar.js
Created November 2, 2021 18:22
Snackbar component
import React, { createContext, useContext, useState, useEffect } from "react";
const SnackbarContext = createContext();
const Provider = ({ children }) => {
const [state, setState] = useState([]);
console.log(state);
return (
<SnackbarContext.Provider value={{ state, setState }}>
@mauriciord
mauriciord / fileHelpers.ts
Last active October 29, 2021 18:55
Creating the file based on the base64
function base64ToArrayBuffer(base64Str: string) {
const byteCharacters = window.atob(base64Str);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
return byteArray;
}
/**
* go to the exercises => http://csbin.io/closures
*
*/
// CHALLENGE 1
function createFunction() {
function sayHello() {
console.log('hello');
}
@mauriciord
mauriciord / createStore.js
Created April 2, 2020 14:38
Create Store function - My own
function createStore(initialState, reducer) {
let state = initialState;
let callback = [];
return {
listen(cb) {
callback = calback.push(cb);
},
dispatch(actionCreator) {
const newState = reducer(state, actionCreator);
@mauriciord
mauriciord / README.md
Created February 28, 2020 19:40
useState and useSafeSetState

Example

import { useSafeSetState } from './custom';

// ...
const [state, safeSetState] = useSafeSetState({ name: '', email: '' })
// ...