CakePHP-Facebook-Plugin icon indicating copy to clipboard operation
CakePHP-Facebook-Plugin copied to clipboard

Getting User information in beforeRender issue

Open robksawyer opened this issue 10 years ago • 1 comments

I'd like to be able to get a Facebook user's information within the beforeRender method and the only way I've been able to do this is using the following method. Is there a better way?

$this->Connect->setAccessToken($this->current_user['facebook_oauth_token']); //Try to reset the oauth token
$this->Connect->uid = $this->current_user['facebook_id'];
$this->Connect->initialize($this);
$this->Connect->startup($this);
$this->facebook_user = $this->Connect->user();

robksawyer avatar Aug 26 '13 07:08 robksawyer

to solve that i've created a Session Variable within the beforeRender of the AppController:

if($this->Auth->loggedIn()){ $id = $this->Auth->user('id'); $logged_user = $this->User->findById($id); //knowing that i've saved all the user details i've grabbed from Facebook in the users table $this->Session->write('LoggedUser', $logged_user); }

this way you can call it from any method of any controller. of course, don't forget to do "$this->Session->destroy();" upon logout.

amjo avatar Aug 26 '13 08:08 amjo