Automatic userId relation on creation
Is there a way to automatically provide a field
userId
(from authenticable entity User
) using the Bearer
token while item creation? I'd like to make the field userId
optional in the request, and provide the requesting user's id
when not provided. I was thinking about using middlewares, but how do I access the current user?2 Replies
@Artur Owczarek I am not sure if I undrestand correctly, which request are you ta lking about ? Login as a User or fetching Users ? Each entity (authenticable or not) as an ID integer as primary column (currently moving to UUIDs). This column is automatically generated. If you want to get the current loggedin user, you can GET
/api/auth/users/me
to receive the logged in user (from the token) with ID and other props. Is that helpful ?
I am logged in as a regular user. I have id and a Bearer token. Now I want to create some items in other collections and assign myself as an owner.
To do so I have to specify field
userId
in the POST
request payload