How to get the current user id?

Hello everybody, im just newbie at phoenix, im trying to build a trello clone and decided to do the backend using phoenix for training and fun, actually i follow this tutorial to do the user part:

Thats okay and it is working, so i created the context of item, and add the board,list and will do cards, but my question for now is how can i use the current user id and add it to the board when being created?

You can see my progress here:
https://github.com/uduDudu/TrelloClone

1 Like

This can be helpful, I have used it in a similar situation:

DockYard – 2 May 16

Phoenix Tips and Tricks - DockYard

Tips and tricks to keep your phoenix code clean and concise

Section: Override action/2 in your controllers

1 Like

Hello,

From the outline you described I’d say that you can obtain the current user id from the session when POSTing to the BoardController.

In there, I assume you’ll call a function inside the Board context to create a new Board.
Pass the current user id as a parameter to the create function. Which in turn will create the association.

If you want some pointers about how you’d create the association, have a look at this: https://elixirschool.com/en/lessons/ecto/associations/

1 Like

Hey man, yeah i can i do it to, didnt think about it, btw thanks for the tutorial and also for updating it, really helped me, thanks for the answer too :smile:

2 Likes

Hey thanks, i will read it

1 Like