@shaddyshad/auth_utils

MongoDB realm auth utils

Usage no npm install needed!

<script type="module">
  import shaddyshadAuthUtils from 'https://cdn.skypack.dev/@shaddyshad/auth_utils';
</script>

README

auth_utils

MongoDB realm auth utils

NPM JavaScript Style Guide

Install

npm install --save @shaddyshad/auth_utils

yarn add @shaddyshad/auth_utils

Usage

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>
    )
  }
}

In the login page

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} />
  )
}

License

MIT © shaddyshad