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
yarn add @exobase/use-basic-auth
# or
yarn add @exobase/hooks
import { useBasicAuth } from '@exobase/use-basic-auth'
// or
import { useBasicAuth } from '@exobase/hooks'
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