@@ -17,12 +17,13 @@ library wp_json_api;
17
17
18
18
import 'package:nylo_support/helpers/auth.dart' ;
19
19
import 'package:nylo_support/local_storage/local_storage.dart' ;
20
+ import 'package:nylo_support/nylo.dart' ;
20
21
import '/helpers/typedefs.dart' ;
21
22
import '/models/wp_user.dart' ;
22
23
import '/networking/network_manager.dart' ;
23
24
24
25
/// The version of the wp_json_api
25
- String _wpJsonAPIVersion = "4.0.3 " ;
26
+ String _wpJsonAPIVersion = "4.0.4 " ;
26
27
27
28
/// The base class to initialize and use WPJsonAPI
28
29
class WPJsonAPI {
@@ -51,10 +52,17 @@ class WPJsonAPI {
51
52
init (
52
53
{required String baseUrl,
53
54
String wpJsonPath = '/wp-json' ,
54
- bool shouldDebug = true }) {
55
+ bool shouldDebug = true ,
56
+ bool nylo = false }) {
55
57
_setBaseApi (baseUrl: baseUrl);
56
58
_setApiPath (path: wpJsonPath);
57
59
_setShouldDebug (value: shouldDebug);
60
+
61
+ // nylo setup
62
+ if (! nylo) {
63
+ Nylo .package ();
64
+ Nylo .instance.addAuthKey (storageKey ());
65
+ }
58
66
}
59
67
60
68
/// Login a user with the [WpUser]
@@ -70,21 +78,14 @@ class WPJsonAPI {
70
78
/// Authenticate a user if they are logged in
71
79
static wpAuth () async {
72
80
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);
77
83
}
78
84
79
85
/// Check if a user is logged in
80
86
static Future <bool > wpUserLoggedIn () async {
81
87
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 ;
88
89
return true ;
89
90
}
90
91
0 commit comments