fastapi-course icon indicating copy to clipboard operation
fastapi-course copied to clipboard

Issue with creation of a Blog

Open emoloic opened this issue 3 years ago • 2 comments

Hello. Thanks for the tutorial. I would like to highlight that the function to create a blog is not completely done. We need to pass the user_id as an argument. But in this demo, this value is set to 1. This means all the blog created will be assigned to user with id=1.

emoloic avatar Dec 02 '22 06:12 emoloic

Just understand the flow and you can fetch the current active username or id. In my case username is primary key in table. And in payload I had passed username and email_id. So while creating a new blog: -

  1. we depend on oauth2 validation.
  2. In oauth2 file we are verifying the token received from login.
  3. So in this case, where we are verifying the token we are returning nothing. Instead of that we can return username or any details from header section of token.
  4. That will be caught at create router in the code and we will pass it to the create in the repository code.
  5. In this way we can get the current active user_name or id.

vksh-chandra avatar Mar 15 '23 11:03 vksh-chandra

@vksh-chandra , thanks for the tutorial, i was going through the above steps, unable to figure out how to fetch the user_id, can you please help us with the code?

vishnutej98 avatar Apr 16 '24 18:04 vishnutej98