Skip to content

createRefresh

Import

import createRefresh from 'react-auth-kit/createRefresh';

Function Signature

createRefresh<T>(createRefreshParamInterface): createRefreshParamInterface<T>

Type Parameters

Name Description
T Type of User State Object

Parameters

Name Type Required Description
param createRefreshParamInterface<T> ✔ Parameters required for the refresh engine

Returns

createRefreshParamInterface<T>

Same params with an added layer of safety net.

Example

const refresh = createRefresh({
    interval: 10,
    refreshApiCallback: async (param) => {
        try {
            const response = await axios.post("/refresh", param, {
                headers: {'Authorization': `Bearer ${param.authToken}`}
            })
            console.log("Refreshing")
            return {
                isSuccess: true,
                newAuthToken: response.data.token,
                newAuthTokenExpireIn: 10,
                newRefreshTokenExpiresIn: 60
            }
        }
        catch(error){
            console.error(error)
            return {
                isSuccess: false
            } 
        }
    }
})

Remarks

This function doesn't really "do anything" at runtime, it just helps to organize the code base Use this function to create the refresh token system


Defined in

packages/react-auth-kit/src/createRefresh.ts:119

— 🔑 —

React Auth Kit is MIT License code