Skip to content

Instantly share code, notes, and snippets.

@IgorDePaula
Created July 2, 2021 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IgorDePaula/6c4e308db9fb0e44ef83541ae05b7a6e to your computer and use it in GitHub Desktop.
Save IgorDePaula/6c4e308db9fb0e44ef83541ae05b7a6e to your computer and use it in GitHub Desktop.
import {createContext, useState} from "react";
export const AuthContext = createContext()
export const AuthProvider = ({children}) => {
const [user, setUser] = useState({})
return <AuthContext.Provider value={[user, setUser]}>
{children}
</AuthContext.Provider>
}
import {Auth} from 'aws-amplify';
import {useContext, useEffect} from 'react'
import {useState} from 'react';
import {useForm} from "react-hook-form";
import {useRouter} from "next/router";
import {XCircleIcon} from "@heroicons/react/solid";
import {AuthContext} from "../src/AuthContext";
export default function Login() {
const {register, handleSubmit} = useForm();
const router = useRouter()
const [user, setUser] = useContext(AuthContext)
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment