The New Way to Build with AI! Introducing ReUI — the developer platform for agentic UI with shadcn/ui
Browse ReUI Pro

How to provide latest valid access token to the data table api call in Metronic 9


HI,

Background:
I am using Remote data source for DataTable in Metronic 9 html + Nextjs, it provides requestHeaders option, which i am using to pass Authorization header with Bearer access token in it to make the server side call pass through the auth.

Problem:
In regular app when api call is failed due to expired access token, i fetch new access token and redo the api call,

How can i provide new access token in the Remote Data Table requestHeaders option incase my access token gets expired.

Although i provided the app context value in the requestHeaders option, but it always uses the data table initialization time context value, instead of the latest value available in the app context.


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)

 
Deleted comment

Hi,

You can try to pass the token via the request header according to your app requirements.

requestHeaders: () => ({
  Authorization: `Bearer ${getLatestAccessToken()}`
})

Regards, Sean


Hi,

Yes when I pass this in the requestHeaders option, the data table is initialized with this option and data is loaded first time,

but lets say access token is expired, and i go to another page or search some thing then how to pass new access token to the data table, as it keep using the old access token given at data initialization time instead of calling the getLatestAccessToken() function again to get the new access token.

As getLatestAccessToken() is called at table initialization time, not afterwards.



Hi,

Thank you for reaching out to us.

Could you please clarify which API you are using?

In most of our APIs, the access token is retrieved during the login process then you can use this token to set the Authorization header.

Regards,
Lauris Stepanovs,
Keenthemes Support Team


Deleted comment
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
buy metronic keenthemes mega bundle

ReUI

Open-source React components, blocks and templates built on shadcn/ui and Tailwind CSS by Keenthemes.