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
{ | |
"colors": { | |
"background": "#FBFBFB", | |
"border": "#F4F4F4", | |
"active": "#F8C924", | |
"inactive": "#C0C0C0" | |
}, | |
"constants": { | |
"borderRadius": 6 | |
}, |
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 function SimpleForm() { | |
const handleSubmit = async (event) => { | |
event.preventDefault(); | |
// Use FormData to get the input values | |
const formData = new FormData(event.target); | |
// Optionally, convert FormData into an object | |
const dataObject = Object.fromEntries(formData); | |
// Process the data | |
await fetch("/api/form", { | |
method: "POST", |
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 { useState } from "react"; | |
export default function SlightlyComplexForm() { | |
const [urlVisible, setUrlVisible] = useState(false); | |
const handleSubmit = async (event) => { | |
// Same as before | |
}; | |
const handleEmailChange = (event) => { |
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 { useForm } from "react-hook-form"; | |
export default function RhfForm() { | |
const { | |
register, | |
handleSubmit, | |
reset, | |
formState: { errors } | |
} = useForm(); |
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 { useForm } from "react-hook-form"; | |
import { zodResolver } from "@hookform/resolvers/zod"; | |
import * as z from "zod"; | |
const schema = z.object({ | |
email: z.string().email().min(2), | |
password: z.string().min(6) | |
}); | |
export default function RhfFormWithZod() { |
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
useEffect(() => { | |
const { data: authListener } = supabase.auth.onAuthStateChange(async (event, session) => { | |
await fetch('/api/set-auth-cookie', { | |
method: 'POST', | |
headers: new Headers({ 'content-Type': 'application/json' }), | |
body: JSON.stringify({ session, event }), | |
}); | |
}); | |
return () => { |
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 { NextRequest, NextResponse } from 'next/server'; | |
export const middleware = async (request: NextRequest) => { | |
if (request.nextUrl.pathname.startsWith('/dashboard')) { | |
const authCookie = request.cookies.get('sb-access-token'); | |
if (!authCookie) return NextResponse.redirect(new URL('/', request.url)); | |
} | |
}; |
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 type { NextApiRequest, NextApiResponse } from 'next'; | |
type User = { userId: string }; | |
const handler = (req: NextApiRequest, res: NextApiResponse<User>) => { | |
return res.status(200).json({ userId: 'abc123' }); | |
}; | |
export default handler; |
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 { Middleware } from 'next-api-route-middleware'; | |
import { getUserByCookie } from '../utils'; | |
export type User = { userId: string }; | |
export type NextApiRequestWithUser = NextApiRequest & User; | |
export const addUser: Middleware<NextApiRequestWithUser> = async (req, res, next) => { | |
const authCookie = await getUserByCookie(); | |
if (authCookie) { |
OlderNewer