updated to use new hws version

This commit is contained in:
2026-02-03 19:11:59 +11:00
parent 563908bbb4
commit 525b3b1396
8 changed files with 49 additions and 26 deletions

View File

@@ -39,9 +39,17 @@ type ContextLoader[T Model] func(ctx context.Context) T
// }
type LoadFunc[T Model, TX DBTransaction] func(ctx context.Context, tx TX, id int) (T, error)
type contextKey string
func (c contextKey) String() string {
return "hwsauth context key" + string(c)
}
var authenticatedModelContextKey = contextKey("authenticated-model")
// Return a new context with the user added in
func setAuthenticatedModel[T Model](ctx context.Context, m authenticatedModel[T]) context.Context {
return context.WithValue(ctx, "hwsauth context key authenticated-model", m)
return context.WithValue(ctx, authenticatedModelContextKey, m)
}
// Retrieve a user from the given context. Returns nil if not set
@@ -53,7 +61,7 @@ func getAuthorizedModel[T Model](ctx context.Context) (model authenticatedModel[
model = authenticatedModel[T]{}
}
}()
model, cok := ctx.Value("hwsauth context key authenticated-model").(authenticatedModel[T])
model, cok := ctx.Value(authenticatedModelContextKey).(authenticatedModel[T])
if !cok {
return authenticatedModel[T]{}, false
}