Added optional onLogout
callback to <Auth />
, inoked when user explicit logout
(calling logout
action) or is kicked out from 401
rejection in call api functions.
Add initialData
prop to <Auth />
.
Useful in SSR scenario when you need to init auth state and avoid running initial side effects.
The initialData
typing:
interface InitialAuthData<A = any, R = any, U = any> {
accessToken: A | null
refreshToken?: R | null
expires?: number | null
user: U | null
}
Types for use-eazy-auth
🎉 !
Now use-eazy-auth
is 100% typescript!
All Routes use-eazy-auth/routes
now has two different props to configure spinners.
The spinner
prop a ReactNode
and a spinnerComponent
prop a ComponentType
.
<AuthRoute path='/' exact spinner={<Spinner />}>
<Dashboard />
</AuthRoute>
<GuestRoute path='/login' exact spinnerComponent={Spinner}>
<Login />
</GuestRoute>
The updateUser
function from useAuthActions
can now acept a callback to
execute a functional update similar to React useState
.
const { updateUser } = useAuthActions()
updateUser(user => ({ ...user, age: user.age + 1 }))
A new component AuthRoutesProvider
is available from use-eazy-auth/routes
,
to configure common part of routes behaviours.
All options can be overridden locally.
Props availables:
interface AuthRoutesConfig<U = any> {
guestRedirectTo?: string | Location<Dictionary>
authRedirectTo?: string | Location<Dictionary>
authRedirectTest?: (user: U) => string | null | undefined | Location
spinner?: ReactNode
spinnerComponent?: ComponentType
rememberReferrer?: boolean
redirectToReferrer?: boolean
}
// All with the same spinner
<AuthRoutesProvider spinner={<Spinner />}>
{/* ... */}
{/* <CustomSpinner /> wins and so on... */}
<AuthRoute path='/' exact spinner={<CustomSpinner />}>
<Dashboard />
</AuthRoute>
</AuthRoutesProvider>
Add setTokens
action to explict set new tokens:
const { setTokens } = useAuthActions()
setTokens({ accessToken: 'NEW_TOKEN' })
// or (if you support refresh token in your use-eazy-auth conf)
setTokens({ accessToken: 'NEW_TOKEN', refreshToken: 'NEW_REFRESH' })
Support React 17 in peerDependencies and bump some build packages, nothing changed.
Fix bug that prevent retriggering login if previous login fail.
This version is bugged fixed in 1.3.0, sorry.
Fix bugged redirectTest
in <AuthRoute />
Component and document it.
This version is bugged fixed in 1.3.0, sorry.
Rewrite the internal logic of effects in RxJS now loginCall
, meCall
and refreshTokenCall
can return Rx Observable.
So you can use rjxs/ajax
without .toPromise()
.
All routes components can be rendered with all methods supported by react-router
.
Now you can do:
<AuthRoute path='/account'>
<Account />
</AuthRoute>
The api still the same of 1.0.0-rc2
published on next tag.
The only breaking change is the remove of callApi()
function from
useAuthActions()
hook, cause is less reliable of callAuthApiPromise()
and
callAuthApiObservable()
.