hook_node_access is not called when user is anonymous

by Mehrdad201   Last Updated July 11, 2018 23:07 PM

I have created a content type that only logged user with specific roles are able to visit or edit it.

but in some cases I wanna give permission to anonymous user to visit specific node. for this issue, I made a form with hook_menu and anonymous user insert user/password and inserted information is correct, in form submission I set a session variable and send the anonymous user to node page (node/$nid) via drupal_goto function. Also I have made hook_node_access function with suitable conditions to give access or not.

I expected that hook_node_access function called but I forced that when user is anonymous this hook is not called!! Only when a user is logged this function called!!

is there any way to give permission to anonymous user in order to visit a specific node id page after form submission?

Tags : forms sessions

Related Questions

Session ID same across browsers

Updated May 09, 2017 17:07 PM

How can unset a Session in drupal 8

Updated March 22, 2017 10:07 AM