SDKsGo SDK
Sessions
Manage user sessions with the HelloJohn Go SDK — list, revoke, and verify sessions server-side.
Sessions
The Go SDK provides a Sessions service for managing user sessions.
hj := hellojohn.New(hellojohn.Config{
TenantID: os.Getenv("HELLOJOHN_TENANT_ID"),
SecretKey: os.Getenv("HELLOJOHN_SECRET_KEY"),
})List Sessions
result, err := hj.Sessions.List(ctx, "usr_01HABCDEF123456")
if err != nil {
log.Fatal(err)
}
for _, session := range result.Sessions {
fmt.Printf("Session %s — IP: %s\n", session.ID, session.IPAddress)
}Filter to active sessions only:
result, err := hj.Sessions.List(ctx, "usr_01HABCDEF123456",
hellojohn.WithStatus("active"),
)Revoke a Session
err := hj.Sessions.Revoke(ctx, "ses_01HABCDEF123456")Revoke All Sessions
Force sign-out all devices for a user:
err := hj.Sessions.RevokeAll(ctx, "usr_01HABCDEF123456")Verify a Session
Real-time session validity check (API-based):
valid, err := hj.Sessions.Verify(ctx, "ses_01HABCDEF123456")
if err != nil || !valid {
http.Error(w, "Session invalid", http.StatusUnauthorized)
return
}Usage Pattern: Password Change
func changePassword(ctx context.Context, userID, newPassword string) error {
// Update password
if _, err := hj.Users.Update(ctx, userID, hellojohn.UpdateUserParams{
Password: newPassword,
}); err != nil {
return err
}
// Invalidate all existing sessions
return hj.Sessions.RevokeAll(ctx, userID)
}