Repository navigation
|
I am building an connectrpc Api for Login. Users can Login with Username and Password. If the user now supplies a wrong password or username, what should i return? With Rest I would return HTTP 401, but how would that be done in gRPC? Should I return an Error or a Ok with a Status Enum? |
Replies: 2 comments
If you want the equivalent of 401, you can return |
|
To handle incorrect usernames or passwords in your gRPC API for login, implement the following: . Return an Error: Use the status code if (!ValidateCredentials(request.Username, request.Password))
{
throw new RpcException(new Status(StatusCode.Unauthenticated, "Invalid username or password"));
}This approach clearly communicates the authentication failure to the client. If you need further assistance, let me know! |
If you want the equivalent of 401, you can return
CodeUnauthenticated. You can see the mapping here