Pricing Blog

Security question (access_token, apikey)

  • uunicode-1272927444076331009

    unicodes

    1 year ago

    Adding the API in variables, as I heard, is not safe because it is visible to anyone. A safe solution is storing the access_token after login and making your API calls using the access_token. How do you manage to hide the API in login steps and when refreshing the access token? I tried to refresh the access token with Bearer access token, but it asks for an API key. Is it enough to use the API key in one variable (like for login or refreshing the access token) to make the app vulnerable. How do you manage this? Are you using an external service like Postman for login and for refreshing the access_token?
  • Security question (access_token, apikey)
  • max.kayr-1272937310593351792

    Max

    1 year ago

    Are you talking about the supabase api key? If so, it is save to store in the browser. Their naming is confusing. This actually is not really an api key. Just don't store the service role key anywhere
  • uunicode-1272948143960494151

    unicodes

    1 year ago

    Yes, I was talking about supabase api key. Thank you Max!
    💪1
  • lucasg-1272954550210531349

    Lucas G

    1 year ago

    The anon key is safe. Service key is not safe
  • Just clarifying lol
  • uunicode-1272972052550258718

    unicodes

    1 year ago

    Thank you Lucas. I'm facing the issue of adding something in the database with the token expired. I have a check if token is expired it works on loading page, but it doesn't work here on the "click". Do you recommend to delete this and add refresh token on error?
    1272972052365574225-Screenshot_2024-08-13_at_20.34.39.png
  • Tod-1272972054420914216

    Tod

    1 year ago

    Great energy @unicodes! Your continuous contribution to the toddle Community just made you advance to Community Level 9!
  • uunicode-1272972315730382901

    unicodes

    1 year ago

    I pressed two times on the insert note, but it doesn't work since I refresh the page.
  • lucasg-1273001751980675188

    Lucas G

    1 year ago

    Assuming you have the refresh token saved somewhere, I’d make this check elsewhere
  • Like on page load as part of the standard user check
  • uunicode-1273001888752734228

    unicodes

    1 year ago

    It is saved in session.
  • lucasg-1273001955580710982

    Lucas G

    1 year ago

    You usually check if the user is logged in on load
  • If not, no data would show
  • So the refresh should happen if that check fails
  • uunicode-1273002472478347448

    unicodes

    1 year ago

    For the situation where you write a note, receive a call and after 1h want to continue and save the note. I want to avoid reload of the page. I was looking for refreshing the token if something happen on the action itself.
  • lucasg-1273002843208552650

    Lucas G

    1 year ago

    First, try extending the token expiry in your backend settings
  • If you’re using supabase, you can do it in your project settings
  • I’m not sure what your process’s use case is here but I’m not sure it’s the correct approach
  • Waiting an hour in the page before continuing could easily be interrupted
  • Actions on the page should be instant and anything requiring such a delay should be handled on the backend
  • But I’m not sure if I understood your scenario properly
  • uunicode-1273004274212929596

    unicodes

    1 year ago

    extending the token expiration could be a solution, but I'm used to work on my mac, than close the display and continue in 1 or 2 hours. And there are situations where I was interrupted of doing things and want to continue after that time. I'm looking to do the refresh exactly before the information is sent. I believe it should be like this, if token is expired then refresh, if not continue, and in any case call the insert api. I have to wait to expire the token now to try this :))
    1273004273927585842-Screenshot_2024-08-13_at_22.43.30.png
  • lucasg-1273005164747554981

    Lucas G

    1 year ago

    What is your condition there?
  • You should likely also extend the expiration
  • uunicode-1273005358121615371

    unicodes

    1 year ago

    1273005357987401909-Screenshot_2024-08-13_at_22.48.38.png