@exobase/use-basic-auth
v1.0.0-rc.31
Published
Exobase basic authentication hook
Downloads
213
Readme
title: 'useBasicAuth' description: 'A basic authentication hook' group: 'Hooks' badge: 'Auth'
Provides a Exobase hook function that will parse out the client id and client secret of an incoming request
NOTE: This hook does not validate the values it parses, you'll need to do that on your own
Install
yarn add @exobase/use-basic-auth
# or
yarn add @exobase/hooks
Import
import { useBasicAuth } from '@exobase/use-basic-auth'
// or
import { useBasicAuth } from '@exobase/hooks'
Usage
You can use useBasicAuth
to parse the client id and client secret from the request. You'll need to validate them yourself.
import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useNext } from '@exobase/use-next'
import { useBasicAuth, BasicAuth } from '@exobase/use-basic-auth'
export const securePingEndpoint = async ({
auth
}: Props<{}, {}, BasicAuth>) => {
console.log(auth) // { clientId: 'abc', clientSecret: 'abc' }
return {
message: 'pong'
}
}
export default compose(useNext(), useBasicAuth(), securePingEndpoint)
In order to keep auth logic out of your endpoints you'll probably want to create a custom hook function to validate