@one-view/auth-helpers
v1.0.3
Published
OneView auth helpers
Downloads
6
Maintainers
Keywords
Readme
@one-view/auth-helpers
Installation
With NPM
$ npm install @one-view/auth-helpers
With Yarn
$ yarn add @one-view/auth-helpers
Usage
Get token and use it inside React component using useToken
hook.
It works hand in hand with useFetchData
hook from @one-view/api-client
package.
import React from 'react'
import ReactDOM from 'react-dom'
import { useToken } from '@one-view/auth-helpers'
import { useFetchData } from '@one-view/api-client'
export const App = () => {
const token = useToken()
const { data } = useFetchData('/endpoint', {
accessToken: token.access_token
})
return <div>{ data }</div>
}
Available Hooks
| Hook name | Descrption |
| :------------- | :------------- |
| useToken
| Returns Token
object |
| useAccessToken
| Returns access_token
value from Token
object |
| useIdToken
| Returns id_token
value from Token
object |
| useProfile
| Returns user's Profile
object |
| useGoogleOpenIDEndpoint
| Returns google Open ID endpoints from Discovery document|
Token
type Token = {
access_token: string
id_token: string
token_type: 'Bearer'
expires_in: number
expires_at: number
}
Profile
type Profile {
name: string
givenName: string
lastName: string
email: string
avatar: string
}