Been working on other stuff in between trying to solve this but I have a 
potential source to the odd behaviour. The page reloads whenever requests 
are sent, is it possible that the requests aren't received when the page is 
reloaded? If this is the case, the error is caught for an invalid user 
because the DB response is fast enough to return before the page reloads, 
but when the user does exist the response is marginally slower such that it 
returns after the page reload. I've been trying to test this by using 
event.preventDefault() 
but this hasn't solved it so I'm not entirely sure.

On Friday, August 20, 2021 at 8:28:02 AM UTC+2 Nicholas Bunn wrote:

> Hi all,
>
> I'm very new to Javascript and everything frontend (started playing around 
> with it all on Monday so any and every kind of input here would be 
> appreciated). I'm currently trying to set up a login page for a project I'm 
> working on which just verifies that a user exists in a DB, checks the 
> passwords, and generates and returns an auth token if everything checks 
> out. I've written all the logic for this in a Go service that exposes 
> itself on port 50000 (I've also tested this service and know that 
> everything here is working). As per the documentation, I've set up an Envoy 
> proxy that routes JS requests on port 8080 to the Go server at 50000 and, 
> as far as I can tell, this is working too. Using Bloom RPC to test things, 
> I've verified that the Envoy Proxy returns the errors I want when incorrect 
> details are provided and returns the auth token when the correct ones are 
> given. 
>
> The relevant code snippet, from my index.js (
> https://github.com/NicholasBunn/mastersCaseStudy/blob/main/services/webFrontend/index.js),
>  
> is:
> ```
> var username = document.getElementById("username").value;
> var password = document.getElementById("password").value;
>
> console.log("Username is: ", username, " and password is: ", password);
> var loginService = new LoginServiceClient("http://localhost:8080";);
>
> var request = new LoginRequest();
>
> request.setUsername(username);
> request.setPassword(password);
>
> loginService.login(request, {}, function (err, res) {
> console.log("error:", err, " response:", res);
> });
> ```
>
> I suspect that the issue I'm having lies somewhere between Envoy and my JS 
> frontend. When I make a login request with no username or an incorrect 
> username, the expected error is written to the console in my browser (it's 
> behaving as intended). However, as soon as I make a login request with an 
> existing username (regardless of whether the password is correct or not), 
> nothing is printed to the console. It's as if the response just skips all 
> the code in the callback function.
>
> If I check the log files for my backend services during this behaviour, 
> the requests are going through and being processed perfectly with the 
> responses being sent back through exactly as expected. I'm not too sure how 
> to debug the proxy, and with that being the last place I can trace expected 
> behaviour I suspect the problem is either in my Envoy setup or in the way 
> I'm handling responses in JS. My Envoy setup can be found at 
> https://github.com/NicholasBunn/mastersCaseStudy/blob/main/services/envoyProxy/envoy.yaml
>  
> - for the most part, it's the same as the Envoy setup given in the 
> documentation.
>
> Am I doing something blatantly wrong here?
>
> Nic
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/cf934f0f-c8ee-4484-926e-de0b243d9c17n%40googlegroups.com.

Reply via email to