Closed LAGGOUNE-Walid closed 2 years ago
I'm not aware Laravel Sanctum supports multiple user providers when using API Token Authentication.
I intend to stay as close as possible to the original Laravel Sanctum package.
I figured out a way to support multiple users login . when executing Login query , the client should specify which user type he is :
mutation {
login(
input: {
usertype: "X"
username: "mario@super.com"
password: "mario"
}
) {
token
user {
... on User {
id
}
}
}
}
and then create union type to group all users in one response type
union authenticatedUser = X | Y | Z
and changed the type of the LoginResponse on sanctum.graphql :
type LoginResponse {
token: String
user: authenticatedUser
}
and also changed the code on Mutations/Login.php
if ($args["usertype"] == "x") {
$provider = "x";
}elseif($args["usertype"] == "y") {
$provider = "y";
}else {
$provider = "z";
}
i hope this could help someone.
Hello , when i modify the lighthouse-sanctum.provider variable to an array of providers an error appears: