getgrav / grav-plugin-login

Grav Login Plugin
http://getgrav.org
MIT License
44 stars 54 forks source link

Can you authenticate user using ajax calls ? #149

Closed coolemur closed 6 years ago

coolemur commented 6 years ago

Looking for a way to check if GRAV registered user has permissions to do specific actions on the website.

Something like:

function isAuthenticated() { $.ajax({ url: "myWebsite/auth", ... }).done(function() { ... if (authenticated) { return true; } else { return false; } }); }

Is this even possible ?

rhukster commented 6 years ago

Never tried that, i'm not sure if the session cookies would be available until you refresh the page.

coolemur commented 6 years ago

@rhukster cookies are not the issue for us (also after ajax call we can save cookies).

Checking if user has permissions to make some actions would be nice tho.

w00fz commented 6 years ago

There is no logic built in for that. You’ll have to create your own endpoint to be reached via Ajax and with all the logic to do the checks you need to do.

The only way to use Ajax for logging in is by simply submitting the form via Ajax but there is no api so what it will do is just hide the submit behind an Ajax call rather than page reload.