0.1.2 • Published 2 years ago
@dmuraco3/react-firebase-auth v0.1.2
Preface
I've created this package because I think authentication should be easier to implement in React.
Table of Contents
Getting Started
Install jest using npm
(yarn coming soon)
npm install --save-dev @dmuraco3/react-firebase-auth
Next, import SessionProvider
into your index.js
import {SessionProvider} from '@dmuraco3/react-firebase-auth'
Then, wrap your components with SessionProvider
and supply firebase config
ReactDOM.render(
<React.StrictMode>
<SessionProvider config={{
apiKey: process.env.REACT_APP_apiKey,
authDomain: process.env.REACT_APP_authDomain,
projectId: process.env.REACT_APP_projectId,
storageBucket: process.env.REACT_APP_storageBucket,
messagingSenderId: process.env.REACT_APP_messagingSenderId,
appId: process.env.REACT_APP_appId,
measurementId: process.env.REACT_APP_measurementID
}}>
<App />
</SessionProvider>
</React.StrictMode>,
document.getElementById('root')
);
Now lets get authorizing, in your App.js file import useAuth
which will return sign in functions and the user object
import {useAuth} from '@dmuraco3/react-firebase-auth'
Now in our component we can access the user and the user functions
function App() {
const {signin, user} = useAuth()
return (
<div>
<button onClick={(e) => {
e.preventDefault()
signin(example@example.com, password)
}}>Sign In</button>
</div>
)
}
Upcoming Changes
- Support for more providers