Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing the currently logged in user object #8

Open
jayrulez opened this issue Mar 22, 2016 · 2 comments
Open

Accessing the currently logged in user object #8

jayrulez opened this issue Mar 22, 2016 · 2 comments

Comments

@jayrulez
Copy link

How can I get access to the currently logged in user object?

A call to $this->getUser(); in an action returns null.

$this->get('security.token_storage')->getToken()->getUser(); only returns the user name.

The code is here: https://github.com/jayrulez/sfapp/blob/9a767712acc747ff34d9a6d6ca35484ebf28af60/src/AppBundle/Controller/UserController.php

@jayrulez
Copy link
Author

I came with a way to get the user object.

I created a service for getting the user based on the username returned from the token getUser()

see method getUser()
https://github.com/jayrulez/sfapp/blob/31a5865d378dd2565fffbd486bff4b586ede47a2/src/AppBundle/Helper/UserHelper.php

However, it all fal s down.

My users immediately lose access to their tokens on the next request after invoking an api call that updates their username.

see setUsernameAction: https://github.com/jayrulez/sfapp/blob/31a5865d378dd2565fffbd486bff4b586ede47a2/src/AppBundle/Controller/UserController.php

This is because the relationships in authbucket are username based instead of id based.

Typically users may change usernames but never their ids.

I think it would be better to make authbucket relationships id based.

@jayrulez
Copy link
Author

I added this workaround to my project:

jayrulez/sfapp@7cdd214

However, I do not think this is a very clean solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant