Search code examples
jsonperlpostgresqldancerapiary.io

Using Dancer2::Plugin::DBIC to pull values from database


I have a webapp where a user can log in and see a dashboard with some data. I'm using APIary for mock data and in my Postgres Database each of my users have an ID. These ID's are also used in the APIary JSON file with relevant information.

I'm using REST::Client and JSON to connect so for example the url for the user's dashboard is: "/user/dashboard/12345" (in Apiary) and in the database there is a user with the ID "12345".

How can I make it so when the user logs in, their ID is used to pull the data that is relevant to them? (/user/dashboard/{id})? Any documentation or advice would be much appreciated!


Solution

  • For those who want to know what I ended up doing:

    Dancer2::Plugin::Auth::Extensible has

    $user = logged_in_user();
    

    When I printed this it showed me a hash of all the values that user had in the database including the additional ID I had. So I accessed the id with

    my $user_id = $user->{user_id};
    

    And appended $user_id to the end of the url!