2.0.1 • Published 2 months ago

@cerebruminc/auth-sdk-react v2.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

Auth SDK for React

This SDK contains hooks for login, register, session info, logout and recovery flow.

flow: flow means whenever user initiate any of the action mentioned above will be indicated as flow. each and every flow has unique id and contains information related to what fields/inputs to render and after submitting form if there is any error then it also contains error messages.

nodes: fields/inputs to render on screen

Installation & usage

As this is private package, you need to setup .npmrc file in the repo where you want to use it. Define CEREBRUM_NPM_TOKEN system wide env variable and then update .npmrc with below contents.

//registry.npmjs.org/:_authToken=${CEREBRUM_NPM_TOKEN}

Contact Cerebrum team for getting CEREBRUM_NPM_TOKEN.

then you can install using

yarn add @cerebruminc/auth-sdk-react

OR

npm install @cerebruminc/auth-sdk-react

then at top level of the app setup AuthSdkProvider.

import { AuthSdkProvider } from '@cerebruminc/auth-sdk-react';
...
...

return (
  <AuthSdkProvider
    kratosUrl="KRATOS_URL_BASED_ON_ENV"
    neuronUrl="NEURON_URL_BASED_ON_ENV">
    <App />
  </AuthSdkProvider>
)

hooks & usage

here are some of the common variables

flow: flow object
loading: if hook is fetching flow information from api
onSubmit: call this function on some form submission
initalValues: inital values to render forms
submitting: if submit actions is in progress

useApiLoginFlow

const { flow, loading, onSubmit, initalValues, submitting } = useApiLoginFlow();

useApiRegisterFlow

const { flow, loading, onSubmit, initalValues, submitting } = useApiRegisterFlow();

useApiLogoutFlow

const logoutFn = useApiLogoutFlow(sessionToken);

useApiSession

const { loading, session, refetch } = useApiSession(sessionToken);

useApiRecoveryFlow

const { loading, onSubmit, flow, submitting } = useApiRecoveryFlow();

useApiVerificationFlow

const { loading, onSubmit, flow, submitting } = useApiVerificationFlow();

utility methods

group parameter is optional in all utility methods. group can be 'default' | 'oidc' | 'password' | 'profile' | 'totp' | 'webauthn' | 'link' | 'lookup_secret'

getInitialValues

this function returns initial values based on nodes

const values = getInitialValues(flow?.ui?.nodes, "group")

getValidationSchema

this function returns yup validation schema

const yupSchema = getValidationSchema(flow?.ui?.nodes, "group")

getFormElements

this function returns fields/inputs to render based on given node and group ( optional )

const fields = getFormElements(flow?.ui?.nodes, "group")
2.0.1

8 months ago

2.0.0

8 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.12

10 months ago

1.0.9

12 months ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago