@@ -17,12 +17,13 @@ library wp_json_api;
1717
1818import 'package:nylo_support/helpers/auth.dart' ;
1919import 'package:nylo_support/local_storage/local_storage.dart' ;
20+ import 'package:nylo_support/nylo.dart' ;
2021import '/helpers/typedefs.dart' ;
2122import '/models/wp_user.dart' ;
2223import '/networking/network_manager.dart' ;
2324
2425/// The version of the wp_json_api
25- String _wpJsonAPIVersion = "4.0.3 " ;
26+ String _wpJsonAPIVersion = "4.0.4 " ;
2627
2728/// The base class to initialize and use WPJsonAPI
2829class WPJsonAPI {
@@ -51,10 +52,17 @@ class WPJsonAPI {
5152 init (
5253 {required String baseUrl,
5354 String wpJsonPath = '/wp-json' ,
54- bool shouldDebug = true }) {
55+ bool shouldDebug = true ,
56+ bool nylo = false }) {
5557 _setBaseApi (baseUrl: baseUrl);
5658 _setApiPath (path: wpJsonPath);
5759 _setShouldDebug (value: shouldDebug);
60+
61+ // nylo setup
62+ if (! nylo) {
63+ Nylo .package ();
64+ Nylo .instance.addAuthKey (storageKey ());
65+ }
5866 }
5967
6068 /// Login a user with the [WpUser]
@@ -70,21 +78,14 @@ class WPJsonAPI {
7078 /// Authenticate a user if they are logged in
7179 static wpAuth () async {
7280 final data = await storageRead (WPJsonAPI .storageKey ());
73- if (data != null ) {
74- return WpUser .fromJson (data);
75- }
76- return null ;
81+ if (data != null ) return null ;
82+ return WpUser .fromJson (data);
7783 }
7884
7985 /// Check if a user is logged in
8086 static Future <bool > wpUserLoggedIn () async {
8187 WpUser ? _wpUser = await wpUser ();
82- if (_wpUser == null ) {
83- return false ;
84- }
85- if (_wpUser.token == null ) {
86- return false ;
87- }
88+ if (_wpUser? .token == null ) return false ;
8889 return true ;
8990 }
9091
0 commit comments