import { useSafeSetState } from './custom';
// ...
const [state, safeSetState] = useSafeSetState({ name: '', email: '' })
// ...
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 { 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() |
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
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()) | |
} |
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
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, |
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
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, | |
}) |
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
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, |
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 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 }}> |
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
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; | |
} |
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
/** | |
* go to the exercises => http://csbin.io/closures | |
* | |
*/ | |
// CHALLENGE 1 | |
function createFunction() { | |
function sayHello() { | |
console.log('hello'); | |
} |
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
function createStore(initialState, reducer) { | |
let state = initialState; | |
let callback = []; | |
return { | |
listen(cb) { | |
callback = calback.push(cb); | |
}, | |
dispatch(actionCreator) { | |
const newState = reducer(state, actionCreator); |
NewerOlder