getEndpointOfType<T extends EndpointRef> method
Returns an endpoint of type T. If more than one endpoint of type T
exists, name can be used to disambiguate.
Usage:
final connectedIdps = await client.auth.idp.getConnectedIdps();
/// Look up an Idp by its name, in this case, the string "email"
final userHasEmailAndPassword = connectedIdps.has('email');
/// Look up an Idp by its type
final userHasGoogleAccount = connectedIdps.has<EndpointGoogleIdpBase>();
Implementation
T getEndpointOfType<T extends EndpointRef>([String? name]) {
if (name != null) {
final endpoint = endpointRefLookup[name] as T?;
if (endpoint == null) {
throw ServerpodClientEndpointNotFound(T, name: name);
}
return endpoint;
}
var foundEndpoints = endpointRefLookup.values.whereType<T>();
switch (foundEndpoints.length) {
case 0:
throw ServerpodClientEndpointNotFound(T);
case 1:
return foundEndpoints.single;
default:
throw ServerpodClientMultipleEndpointsFound(T, foundEndpoints);
}
}