best way to store data in a session supabase and toddle

  • ssssadsadasd-1328373980100432043

    ssssadsadasd

    26 days ago

    In bubble you can easily add new columns to a user table and then easily access those columns through e.g. "current user's profile picture". In supabase you cannot add new columns to authentication and thus you need to add a new table with such columns as profile pic, first name, last name, etc.

    Now, I would need to have easy access to these values. What is the best way I can store these variables of the current user (profile pic, first name, last name, etc.) in the session for easy access so that I do not have to make an api call everytime I need them?

    So, the moment the user logs in the variables are stored and, ideally, they are updated automatically if the user changes them

    Thanks
    πŸ‘1
  • ssssadsadasd-1328374457420746913

    ssssadsadasd

    26 days ago

    [this](https://discord.com/channels/972416966683926538/1274310112143609866) was very helpful but I would probably need some more practical suggestions with my example above
  • yoelfdz-1328466499530133505

    yoelfdz

    26 days ago

    You can make the api call on the app-root or page level, set an event on success that updates a variable with the data and you can either [expose a formula in the context](https://www.youtube.com/watch?v=KHCopeS0Fk4&t=350s) so it's easy accesible or work you way down in [abstraction](https://www.youtube.com/watch?v=PQjMZ_0ju1g) passing the data through attributes to components
    πŸ‘1
  • building_stuff-1328473816602775573

    Janis

    26 days ago

    You can attach them to auth.users raw_metadata. You can then make a call to auth users to update the users metadata like first name, profile pic whatever you need
  • lucasg-1328560590444040306

    Lucas G

    25 days ago

    As Janis said, you can store it in auth.users metadata
  • If you need admins/users to be able to edit another user's data though, you need to create your own user's table
  • auth table data can only be accessed/updated by that user
  • ssssadsadasd-1329032259222638665

    ssssadsadasd

    24 days ago

    @Janis @Lucas G thanks for the input. I managed to implement this. how can I then access the profile_id below from the cookies:

    {

    "sub": "072253c3-31d8-4299-a6b6-2263db4603c1",
    "aud": "authenticated",
    "exp": 1736939458,
    "iat": 1736935858,
    "email": "test1@gmail.com",
    "phone": "",
    "app_metadata": {
    "provider": "email",
    "providers": [
    "email"
    ]
    },
    "user_metadata": {
    "profile_id": 6,
    "profile_image": "test1"
    },
    "role": "authenticated",
    "aal": "aal1",
    "amr": [
    {
    "method": "password",
    "timestamp": 1736935858
    }
    ],
    "session_id": "6b975bcf-e75d-4d83-8a5a-6269e8385f67",
    "is_anonymous": false
    }
  • I used jwt.io, pasted the access token, and this was shown under payload data
  • building_stuff-1329041868188680232

    Janis

    24 days ago

    Make a GET request to /auth/v1/user and then you'll find it under user_metadata in the response
  • Tod-1329041870298288158

    Tod

    24 days ago

    Great energy @Janis! Your continuous contribution to the toddle Community just made you advance to Community Level 8!
  • ssssadsadasd-1329046111737876480

    ssssadsadasd

    24 days ago

    @Janis so I still need to make an api call?
  • building_stuff-1329047113132412949

    Janis

    24 days ago

    Yes, well you anyways need to make the call to check if it is an authenticated user right? So it won’t save you the call but an additional call to let’s say a profile table or so
  • ssssadsadasd-1329047358259986532

    ssssadsadasd

    24 days ago

    ah ok, I thought I could simply check whether the access_token was not empty (for authentication) and then somehow access the metadata from it
  • building_stuff-1329047757515919383

    Janis

    24 days ago

    So after a user logs in you have to secure your pages and calls. So what most of us do is to have a wrapper component that does the auth call and then based on the authentication status the child elements/ components are shown (the actual app)
  • Like if you don’t do the api call then there is no way of saying whether a user is authenticated
  • ssssadsadasd-1329048378704658443

    ssssadsadasd

    24 days ago

    ok, understood. that was a question down on the line on page redirect. thanks.
    by wrapper component you mean like a page? so if i want a page accessible only to authenticated users I do: on page lifecycle -> on load -> get auth and redirect based on that result? thanks
  • building_stuff-1329048946927992863

    Janis

    24 days ago

    Almost: I can share a screenshot later but the idea is:

    - you have the Supabase auth call set to auto fetch
    - you have a page with a component/element called e.g auth-wrapper -> here you add your app elements as children
    - the auth-wrapper has a conditional show based on the success of the Supabase auth call
    βœ…2
  • ssssadsadasd-1329049191858831431

    ssssadsadasd

    24 days ago

    got it thanks
    πŸ‘1
  • building_stuff-1329049343881117779

    Janis

    24 days ago

    Just make sure to set your session token based on the success of the sign in event
    πŸ‘1

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code β€” but accessible to your entire team!

Try toddle β€” it's free!

Β© Copyright 2024 toddle. All rights reserved.