Can anyone tell me how can i renew session?? Problem : When the access token expires my backend api ...
a
Can anyone tell me how can i renew session?? Problem : When the access token expires my backend api throws 401 so i want to renew user session / or regenerate accessToken instead of redirecting to logout
r
hey @abhaybisht2002 if you are using our frontend sdk and have configured the apiDomain correctly, session refreshing should happen on its own
a
so will it trigger everytime my api throw 401
?
r
yes
it should
as long as you have configured it correctly
a
this is my config, is it correct?
r
no idea
depends on your use case and setup
Sorry, your questions will have to be very specific here
a
@rp_st i'm facing one more issue supertoken is passing Authorization : Bearer token toke my own api so what ever token that i'm giving is overwritten by supertoken
how can i fix this?
r
how are you making api calls? share a snippet
a
is there any particular specification for that?? as this frontend config is exactly same as mentioned in the documentation
r
and what auth header are you giving to your api calls?
well, im really not sure the kind of issues you are facing. And you are being very vague overall
and this is a free service we are providing
a
eg:
Copy code
jsx
function createAxiosInstance() {
    const instance = axios.create({
        baseURL: process.env.NEXT_PUBLIC_BACKEND_BASE_URL,
        withCredentials: true
    })
    // Request Interceptor
    instance.interceptors.request.use((config) => {
        return config
    }, (error) => {
        return Promise.reject(error)
    })
    // Response Interceptor
    instance.interceptors.response.use((response) => {
        return response.data
    }, (error) => {
        return Promise.reject(error)
    })
    return instance
}

const AxiosContext = createContext<axiosContextType | undefined>(undefined)

export function AxiosProvider({ children }: { children: React.ReactNode }) {

    const axiosInstance: AxiosInstance = useMemo(() => createAxiosInstance(), [])

    const values: axiosContextType = {
        axiosInstance
    }
Copy code
jsx
   const getApiKeysByProjectId = async () => {
        if (selectedProject && selectedProject.id) {
            try {
                const response = (await axiosInstance(``)) as ApiKeyType[]
                setApiKeys(response)
            } catch (err) {
                isUnauthorized(err, router)
            }
        } else {
            console.warn("No project selected")
        }
    }
Authorization
r
can i see exactly how you are adding your own auth header to an api call?
please dont just dump all the code and expect us to go through it
keep your questions as clear and as small as possible if you want us to help.
a
you are asking for code
r
oh yea. But a very specific part of it. Anyway, good lluck! hope you figure it out.
3 Views