AlexxIT/go2rtc · error
invalid auth type
Error message
invalid auth type
What it means
The Ring client factory only accepts RefreshTokenAuth or EmailAuth; any other auth type (nil, a wrong struct type, or a different interface value) falls into the default branch and is rejected with this error. It is a strict type check on the auth argument.
Solutions
- Pass ring.RefreshTokenAuth{...} or ring.EmailAuth{...} by value, not a pointer or foreign type.
- If you hold a pointer, dereference it before passing.
- Check the exact accepted types in pkg/ring/api.go and match them.
- Default to RefreshTokenAuth, the recommended auth mode.
Example fix
// before
client, err := ring.NewClient(&ring.EmailAuth{Email: e, Password: p}) // pointer rejected
// after
client, err := ring.NewClient(ring.EmailAuth{Email: e, Password: p}) Defensive patterns
Strategy: type-guard
Validate before calling
switch a := auth.(type) {
case ring.RefreshTokenAuth, ring.EmailAuth:
// ok
default:
return errors.New("auth must be ring.RefreshTokenAuth or ring.EmailAuth (by value)")
} Type guard
func validRingAuth(a any) bool {
switch a.(type) {
case ring.RefreshTokenAuth, ring.EmailAuth:
return true
}
return false
} Try / catch
client, err := ring.NewClient(auth)
if err != nil && err.Error() == "invalid auth type" {
return fmt.Errorf("wrong auth type %T passed to ring.NewClient: %w", auth, err)
} Prevention
- Pass auth structs by value, never pointers, into the factory
- Do not pass foreign/other-library credential types
- Centralize auth construction in one helper so the type is checked once
- Add a compile-time usage example in tests to catch type drift
When it happens
Trigger: Passing nil as auth, a pointer to EmailAuth/RefreshTokenAuth instead of the value type (type switch is on values), or some other credential struct the factory does not know.
Common situations: Passing &ring.EmailAuth{...} (pointer) into a value-typed type switch; passing credentials from another library's auth type; calling the factory without any auth argument.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- refresh token is required
- email and password are required
- failed to parse refresh token
- streams: source empty
- loginResp.ErrorMsg
AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07).
Data as JSON: /api/errors/96bb7a9d2391a13f.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/ring/api.go:172
)
func NewRestClient(auth interface{}, onTokenRefresh func(string)) (*RingApi, error) {
var cacheKey string
// Create cache key based on auth data
switch a := auth.(type) {
case RefreshTokenAuth:
if a.RefreshToken == "" {
return nil, fmt.Errorf("refresh token is required")
}
cacheKey = "refresh:" + a.RefreshToken
case EmailAuth:
if a.Email == "" || a.Password == "" {
return nil, fmt.Errorf("email and password are required")
}
cacheKey = "email:" + a.Email + ":" + a.Password
default:
return nil, fmt.Errorf("invalid auth type")
}
cacheMutex.Lock()
defer cacheMutex.Unlock()
if cachedClient, ok := clientCache[cacheKey]; ok {
// Check if token is not nil and not expired
if cachedClient.authToken != nil && time.Now().Before(cachedClient.tokenExpiry) {
cachedClient.onTokenRefresh = onTokenRefresh
return cachedClient, nil
}
}
client := &RingApi{
httpClient: &http.Client{Timeout: defaultTimeout},
onTokenRefresh: onTokenRefresh,
hardwareID: generateHardwareID(),
auth: auth,View on GitHub (pinned to c245815e75)