@exobase/use-basic-auth
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc.31 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @exobase/use-basic-auth

Weekly Downloads

80

Version

1.0.0-rc.31

License

MIT

Unpacked Size

18.3 kB

Total Files

17

Last publish

Collaborators

  • rayepps