Skip to content

Commit

Permalink
PR suggestion applyToRoute > applies
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzanardo committed Jun 23, 2023
1 parent b4886bc commit 5adeff5
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/basic_authentication/routes/users/[id].dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:io';

import 'package:basic_authentication/user_repository.dart';
import 'package:dart_frog/dart_frog.dart';
import 'package:example/user_repository.dart';

Future<Response> onRequest(RequestContext context, String id) async {
return switch (context.request.method) {
Expand Down
4 changes: 2 additions & 2 deletions examples/basic_authentication/routes/users/_middleware.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:basic_authentication/user_repository.dart';
import 'package:dart_frog/dart_frog.dart';
import 'package:dart_frog_auth/dart_frog_auth.dart';
import 'package:example/user_repository.dart';

Future<User?> Function(String, String) userFromCredentials(
UserRepository repository,
Expand All @@ -17,7 +17,7 @@ Handler middleware(Handler handler) {
.use(
basicAuthentication<User>(
userFromCredentials: userFromCredentials(userRepository),
applyToRoute: (RequestContext context) async =>
applies: (RequestContext context) async =>
context.request.method != HttpMethod.post,
),
);
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_authentication/routes/users/index.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:io';

import 'package:basic_authentication/user_repository.dart';
import 'package:dart_frog/dart_frog.dart';
import 'package:example/user_repository.dart';

Future<Response> onRequest(RequestContext context) async {
return switch (context.request.method) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ignore_for_file: prefer_const_constructors

import 'package:example/user_repository.dart';
import 'package:basic_authentication/user_repository.dart';
import 'package:test/test.dart';

void main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import 'dart:io';

import 'package:basic_authentication/user_repository.dart';
import 'package:dart_frog/dart_frog.dart';
import 'package:example/user_repository.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import 'dart:io';

import 'package:basic_authentication/user_repository.dart';
import 'package:dart_frog/dart_frog.dart';
import 'package:example/user_repository.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

Expand Down
4 changes: 2 additions & 2 deletions packages/dart_frog_auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ only an authenticated user would be allowed to change this information.

To accomplish that, we need the middleware to apply authentication to all routes except `POST`.

Such behavior is possible with the use of the `applyToRoute` optional predicate:
Such behavior is possible with the use of the `applies` optional predicate:

```dart
Handler middleware(Handler handler) {
Expand All @@ -189,7 +189,7 @@ Handler middleware(Handler handler) {
.use(
basicAuthentication<User>(
userFromCredentials: userFromCredentials(userRepository),
applyToRoute: (RequestContext context) async =>
applies: (RequestContext context) async =>
context.request.method != HttpMethod.post,
),
);
Expand Down
8 changes: 4 additions & 4 deletions packages/dart_frog_auth/lib/src/dart_frog_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ Future<bool> _defaultApplyToRoute(RequestContext context) async => true;
/// apply to the route and the call will have authentication validation.
Middleware basicAuthentication<T extends Object>({
required Future<T?> Function(String, String) userFromCredentials,
ApplyToRoute applyToRoute = _defaultApplyToRoute,
ApplyToRoute applies = _defaultApplyToRoute,
}) =>
(handler) => (context) async {
if (!await applyToRoute(context)) {
if (!await applies(context)) {
return handler(context);
}

Expand Down Expand Up @@ -91,10 +91,10 @@ Middleware basicAuthentication<T extends Object>({
/// apply to the route and the call will have no authentication validation.
Middleware bearerAuthentication<T extends Object>({
required Future<T?> Function(String) userFromToken,
ApplyToRoute applyToRoute = _defaultApplyToRoute,
ApplyToRoute applies = _defaultApplyToRoute,
}) =>
(handler) => (context) async {
if (!await applyToRoute(context)) {
if (!await applies(context)) {
return handler(context);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/dart_frog_auth/test/src/dart_frog_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void main() {
called = true;
return user;
},
applyToRoute: (_) async => false,
applies: (_) async => false,
);

await middleware((_) async => Response())(context);
Expand Down Expand Up @@ -227,7 +227,7 @@ void main() {
called = true;
return user;
},
applyToRoute: (_) async => false,
applies: (_) async => false,
);

await middleware((_) async => Response())(context);
Expand Down

0 comments on commit 5adeff5

Please sign in to comment.