diff --git a/README.md b/README.md index 48417401..006fbbe8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # angel_auth -[![version 1.1.0-dev+15](https://img.shields.io/badge/version-1.1.0--dev+15-red.svg)](https://pub.dartlang.org/packages/angel_auth) +[![version 1.1.0-dev+16](https://img.shields.io/badge/version-1.1.0--dev+16-red.svg)](https://pub.dartlang.org/packages/angel_auth) ![build status](https://travis-ci.org/angel-dart/auth.svg?branch=master) A complete authentication plugin for Angel. Inspired by Passport. diff --git a/lib/src/plugin.dart b/lib/src/plugin.dart index 77705ec9..696719a1 100644 --- a/lib/src/plugin.dart +++ b/lib/src/plugin.dart @@ -238,22 +238,20 @@ class AngelAuth extends AngelPlugin { ..inject(AuthToken, req.properties['token'] = token) ..inject(result.runtimeType, req.properties["user"] = result); - if (allowCookie) req.cookies.add(new Cookie("token", jwt)); + if (allowCookie) res.cookies.add(new Cookie("token", jwt)); if (options?.callback != null) { return await options.callback(req, res, jwt); } - if (options?.canRespondWithJson != false && + if (options?.successRedirect?.isNotEmpty == true) { + return res.redirect(options.successRedirect, code: HttpStatus.OK); + } else if (options?.canRespondWithJson != false && req.headers.value("accept") != null && (req.headers.value("accept").contains("application/json") || req.headers.value("accept").contains("*/*") || req.headers.value("accept").contains("application/*"))) { return {"data": result, "token": jwt}; - } else if (options != null && - options.successRedirect != null && - options.successRedirect.isNotEmpty) { - return res.redirect(options.successRedirect, code: HttpStatus.OK); } return true; @@ -281,7 +279,7 @@ class AngelAuth extends AngelPlugin { } } - req.cookies.removeWhere((cookie) => cookie.name == "token"); + res.cookies.removeWhere((cookie) => cookie.name == "token"); if (options != null && options.successRedirect != null && diff --git a/pubspec.yaml b/pubspec.yaml index 6ce73f76..7c81491e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_auth description: A complete authentication plugin for Angel. -version: 1.0.0-dev+15 +version: 1.0.0-dev+16 author: Tobe O homepage: https://github.com/angel-dart/angel_auth dependencies: