cakephp / authentication

Authentication plugin for CakePHP. Can also be used in PSR7 based applications.
MIT License
115 stars 101 forks source link

Use Authentication into Cell #666

Closed JessyLELIEVRE closed 3 months ago

JessyLELIEVRE commented 3 months ago

Hello,

I'm contacting you to let you know that I'd like to be able to use and browse authentication information in the "component" way in Cells.

Do you have a temporary idea for how to do this? *

Thank you,

markstory commented 3 months ago

I'm contacting you to let you know that I'd like to be able to use and browse authentication information in the "component" way in Cells.

You can access the authentication service via the request attribute request->getAttribute('authentication') and the current identity is available on request->getAttribute('identity').

I'm interested in what kind of scenarios you need the component to be available in a cell for.

JessyLELIEVRE commented 3 months ago

Hello,

I'd like to use the identity component to retrieve user information from a cell.

My user has a side navigation bar. It contains information such as username, e-mail address and number of credits (virtual currencies). When my player makes a purchase, I take care to update the player session, as I don't want to perform a SQL query simply and solely to retrieve the information (except during the purchase for security checks).

That's why I want to be able to use the identity component from a cell.

Thank you in advance,

markstory commented 3 months ago

Could you use the IdentityHelper for that?

JessyLELIEVRE commented 3 months ago

Could you use the IdentityHelper for that?

Hello,

Yep. I can. But that doesn't resolve my use case.

A simple example of the use case I'd like:

public function userCard(string $userAvatar = null) { $user = $this->fetchTable('Users')->get([...], select: ['Users.id','Users.username','Users.credits']); $this->set(compact('user', 'userAvatar')); }

Thank you in advance,

ADmad commented 3 months ago

@JessyLELIEVRE As already stated by markstory in his initial comment you can get the user identity from the request instance $this->request->getAttribute('identity').

JessyLELIEVRE commented 3 months ago

@JessyLELIEVRE As already stated by markstory in his initial comment you can get the user identity from the request instance $this->request->getAttribute('identity').

Hello,

All right, I'll do it this way.

Thank you so much,