How to re-direct to a webpage upon requestAuthentification() failling #11457
Unanswered
AIoT-Consulting
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In the esp32 WebServer.h library, I've been referencing the HttpAdvancedAuth.ino example file to figure out how to add authentication when linking to a specific webpage and was wondering if anyone else is tried to re-direct to a webpage upon the requestAuthentication() method failling when a user enters the wrong credentials or hits "Cancel". For example, when a user enters the IP address of the eps32 (ex: 192.168.50.197) , my code contains the following:
server.on("/", handleRoot);
which calls:
htmlPage1 being a const char containing the html code stored in SPIFF memory.
So far so good.
Now on my htmlPage1, if the users want to access another page called "Settings", they click on a link
<a href="/page2">Settings</a>
and I have the following code to handle the /page2 call:Again, so far so good as the authentification pops up,

and if the user enters the right credential, htmlPage2 opens up.
The problem I'm trying to address is what happens when the user hits the "Cancel" button after trying and failling to enter their credential. What currently happens is when the user clicks on "Cancel" the following screen appears:
And the user is not re-directed to any page.
I've tried adding
server.send(200, "text/html", htmlPage1);
under theserver.requestAuthentication(DIGEST_AUTH, www_realm, authFailResponse);
as well as all kinds of other ways to make this happen without any success. Here are the values of the www_realm and authFailResponse variables:I'm hoping someone who has better knowledge of the webserver.h library can help me find a way to solve this by having the user re-directed to the original root page upon failling the authentication or clicking the "Cancel" button.
Thanks for any help...
Beta Was this translation helpful? Give feedback.
All reactions