Refactor EditorSession model to include token in props and update JSON parsing; simplify route handlers by removing JWT manager parameter

This commit is contained in:
Leon Bösche
2026-01-10 05:02:07 +01:00
parent 941d8bf736
commit 84c7ed0815
2 changed files with 8 additions and 5 deletions

View File

@@ -2,21 +2,24 @@ import 'package:equatable/equatable.dart';
class EditorSession extends Equatable { class EditorSession extends Equatable {
final Uri editUrl; final Uri editUrl;
final String token;
final bool readOnly; final bool readOnly;
final DateTime expiresAt; final DateTime expiresAt;
const EditorSession({ const EditorSession({
required this.editUrl, required this.editUrl,
required this.token,
required this.readOnly, required this.readOnly,
required this.expiresAt, required this.expiresAt,
}); });
@override @override
List<Object?> get props => [editUrl, readOnly, expiresAt]; List<Object?> get props => [editUrl, token, readOnly, expiresAt];
factory EditorSession.fromJson(Map<String, dynamic> json) { factory EditorSession.fromJson(Map<String, dynamic> json) {
return EditorSession( return EditorSession(
editUrl: Uri.parse(json['editUrl']), editUrl: Uri.parse(json['editUrl']),
token: json['token'] ?? '',
readOnly: json['readOnly'], readOnly: json['readOnly'],
expiresAt: DateTime.parse(json['expiresAt']), expiresAt: DateTime.parse(json['expiresAt']),
); );

View File

@@ -104,10 +104,10 @@ func NewRouter(cfg *config.Config, db *database.DB, jwtManager *jwt.Manager, aut
// Org routes // Org routes
r.Get("/orgs", func(w http.ResponseWriter, req *http.Request) { r.Get("/orgs", func(w http.ResponseWriter, req *http.Request) {
listOrgsHandler(w, req, db, jwtManager) listOrgsHandler(w, req, db)
}) })
r.Post("/orgs", func(w http.ResponseWriter, req *http.Request) { r.Post("/orgs", func(w http.ResponseWriter, req *http.Request) {
createOrgHandler(w, req, db, auditLogger, jwtManager) createOrgHandler(w, req, db, auditLogger)
}) })
// Org-scoped routes // Org-scoped routes
@@ -243,7 +243,7 @@ func logoutHandler(w http.ResponseWriter, r *http.Request, jwtManager *jwt.Manag
w.Write([]byte(`{"status": "ok"}`)) w.Write([]byte(`{"status": "ok"}`))
} }
func listOrgsHandler(w http.ResponseWriter, r *http.Request, db *database.DB, jwtManager *jwt.Manager) { func listOrgsHandler(w http.ResponseWriter, r *http.Request, db *database.DB) {
// User ID is already set by Auth middleware // User ID is already set by Auth middleware
userIDStr, ok := middleware.GetUserID(r.Context()) userIDStr, ok := middleware.GetUserID(r.Context())
if !ok { if !ok {
@@ -263,7 +263,7 @@ func listOrgsHandler(w http.ResponseWriter, r *http.Request, db *database.DB, jw
json.NewEncoder(w).Encode(orgs) json.NewEncoder(w).Encode(orgs)
} }
func createOrgHandler(w http.ResponseWriter, r *http.Request, db *database.DB, auditLogger *audit.Logger, jwtManager *jwt.Manager) { func createOrgHandler(w http.ResponseWriter, r *http.Request, db *database.DB, auditLogger *audit.Logger) {
// User ID is already set by Auth middleware // User ID is already set by Auth middleware
userIDStr, ok := middleware.GetUserID(r.Context()) userIDStr, ok := middleware.GetUserID(r.Context())
if !ok { if !ok {