MongoDB realm auth utils
npm install --save @shaddyshad/auth_utils
yarn add @shaddyshad/auth_utils
import React, { Component } from 'react'
import {AuthContextProvider} from 'auth_utils'
// declare the app id from mongo db realm
const appId = "YOUR_REALM_APP_ID"
class Example extends Component {
render() {
return (
<AuthContextProvider appId={appId} >
<OtherComponents />
</AuthContextProvider>
)
}
}
import React, {useState} from 'react'
import {useAuth} from 'auth_utils'
const Signin = (props) => {
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
const auth = useAuth()
const onSignin = () => {
auth.login(email, password)
.then(() => {
// succesfully signed in
}).catch(err => {
// handle the error
// {error: str, error_code: str...}
})
}
return (
<SigninUi onSigin={onSigin} />
)
}
MIT © shaddyshad