Check if user is logged in from front-end

Max De Los Reyes asked on March 29, 2023 01:11

Hello. Working in Kentico 10.

I have a frontend application that sends an object to the backend using an AJAX call to a web service when a user clicks a button. However, it's required that users must log in before saving any data. I thought to check for authentication then redirect to the login page from the backend using Response.Redirect/URLHelper.Redirect, but I've learned that these methods are incompatible with web services due to the nature of the request.

I'm now thinking that I should check for login before ever sending the AJAX. What's the best way to verify, with JavaScript, that a user is logged in?

I've considered placing in a web part that checks for login and sets a HiddenField value to true/false depending on the outcome, then allowing the JavaScript to grab that value and make/not make the request depending on the T/F, but that's relatively easy to bypass. What else can I do? I haven't been able to find anything related to this in Kentico's documentation.

Recent Answers


Ashish Kashyap answered on March 29, 2023 06:25

You can verify this in AJAX back-end call. If authenticated proceed else return false.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.