updated to use new hws version
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user