Skip to content

Commit 316987c

Browse files
committed
Finished error management
1 parent f6adac1 commit 316987c

19 files changed

+786
-572
lines changed

docs/package.json

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
2-
"name": "flutter_feathersjs",
3-
"version": "0.0.1",
4-
"description": "Communicate with your feathers js server from flutter",
5-
"main": "index.js",
6-
"authors": {
7-
"name": "Justin Y. Dah-kenangnon",
8-
"email": "dah.kenangnon@gmail.com"
9-
},
10-
"repository": "https://github.com/Dahkenangnon/flutter_feathersjs.dart/flutter_feathersjs",
11-
"scripts": {
12-
"dev": "vuepress dev src",
13-
"build": "vuepress build src"
14-
},
15-
"license": "MIT",
16-
"devDependencies": {
17-
"@vuepress/plugin-nprogress": "^1.7.1",
18-
"vuepress": "^1.5.3"
19-
}
20-
}
2+
"name": "flutter_feathersjs",
3+
"version": "0.0.1",
4+
"description": "Communicate with your feathers js server from flutter",
5+
"main": "index.js",
6+
"authors": {
7+
"name": "Justin Y. Dah-kenangnon",
8+
"email": "dah.kenangnon@gmail.com"
9+
},
10+
"repository": "https://github.com/Dahkenangnon/flutter_feathersjs.dart/flutter_feathersjs",
11+
"scripts": {
12+
"dev": "vuepress dev src",
13+
"build": "vuepress build src",
14+
"up": "ncu -u && yarn install"
15+
},
16+
"license": "MIT",
17+
"devDependencies": {
18+
"@vuepress/plugin-nprogress": "^1.8.2",
19+
"vuepress": "^1.8.2"
20+
}
21+
}

docs/src/guide/README.md

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
11
# Introduction
22

3-
## :bird: flutter_feathersjs :bird:
3+
## :bird: flutter_feathersjs :bird
44

55
Communicate with your feathers js [https://feathersjs.com/](https://feathersjs.com/) server from flutter.
66

77
`Infos: Feathers js is a node framework for real-time applications and REST APIs.`
88

9-
*__FormData support out the box, auth, reAuth, socketio send event, rest ...__
9+
*__FormData support out the box, auth, reAuth, socketio send event, rest ...__
1010

11-
## Illustration's service infos
11+
## Infos
1212

13-
In this documentation, we assume that our feathers js api has a **news** services register on **/news**
13+
In this documentation, we are using the demo api and app for illustration. See at the bottom for demo's link.
1414

15-
with the following schema
15+
## Demo
1616

17-
```js
17+
Feathers demo api repo here: [On Github](https://github.com/Dahkenangnon/flutter_feathersjs.dart)
1818

19-
// News schema
20-
const schema = new Schema({
19+
Feathers demo api site: [On heroku](https://flutter-feathersjs.herokuapp.com/)
2120

22-
title: { type: String, required: true },
23-
24-
content: { type: String, required: true },
25-
26-
// They can provide multiple image for a single news
27-
files: { type: Array, required: false },
28-
29-
//The publisher id
30-
author: { type: Schema.Types.ObjectId, ref: 'users', required: true },
31-
32-
}, {
33-
timestamps: true
34-
});
35-
```
36-
37-
## The illustration's app
38-
39-
The app used for this documentation will be available very soon.
21+
Flutter demo app: [On Github](https://github.com/Dahkenangnon/flutter_feathersjs_demo_app)

docs/src/guide/authentication.md

Lines changed: 109 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,142 @@
11
# Authentication
22

3-
Because we have two parts (scoketio and rest) which must communicate
4-
with the same server (which required maybe authentication) we must found a way to authenticate
3+
Because we have two parts (scketio and rest) which must communicate
4+
with the same server (which required maybe authentication) we must found a way to authenticate
55
both rest & socketio once user is logged.
66

7-
Below, how to authenticate rest only or socketio only. But notice that in a production app,
7+
Below, how to authenticate rest only or socketio only. But notice that in a production app,
88
you don't need to auth speratly the different client, just use the global authentication method.
9-
Nice ? Go
9+
Nice ? Go :rocket:
1010

11-
## Auth rest
11+
## Rest only
1212

1313
You can for testing purpose only authenticate the rest client by doing the following.
1414
Note that when you use an other stratagy different from email/pass strategy, you must configure it on your server.
1515

1616
```dart
17-
// Auth with rest client with email/password [Default strategy]
18-
var authResponse = await flutterFeathersjs.rest
19-
.authenticate(userName: "mail@mail.com", password: "Strong_Pass");
20-
21-
// Or
22-
23-
// Auth with rest client with phone/password strategy
24-
var authResponse = await flutterFeathersjs.rest.authenticate(
25-
strategy: "phone",
26-
userNameFieldName: "tel",
27-
userName:"+22900000000",,
28-
password: "Strong_Pass");
17+
try {
18+
var user = await flutterFeathersjs.rest.authenticate(
19+
userName: "dah.kenangnon@flutter_feathersjs.com",
20+
password: "flutter_feathersjs");
21+
//TODO: Authentication is Ok, save user in local storage
22+
23+
} on FeatherJsError catch (e) {
24+
if (e.type == FeatherJsErrorType.IS_INVALID_CREDENTIALS_ERROR) {
25+
//TODO: Invalid credentials
26+
} else if (e.type == FeatherJsErrorType.IS_INVALID_STRATEGY_ERROR) {
27+
//TODO: Invalid strategy
28+
} else if (e.type == FeatherJsErrorType.IS_AUTH_FAILED_ERROR) {
29+
//TODO: Invalid authentication failed for other reason.
30+
// verbose => print(e.message);
31+
}
32+
//TODO: Check for other FeatherJsErrorType
33+
// => print(e.type);
34+
} catch (e) {
35+
//TODO: Authentication failed for unkknown reason.
36+
// why => print(e.type);
37+
// why => print(e.message);
38+
}
2939
3040
```
3141

32-
## Auth socketio
42+
## Socketio only
3343

34-
The process to authenticate the socketio client is done after rest auth is os because,
35-
it using the JWT retrieved by rest client when process finished with ok.
44+
The process to authenticate the socketio client is done after rest auth is done because,
45+
it use the JWT retrieved by rest client when process finished with ok.
3646

3747
```dart
48+
3849
// Note: This must be call after rest auth success
3950
// Not recommanded to use this directly
40-
var authResponse = await flutterFeathersjs.scketio.authWithJWT();
51+
try {
52+
bool isReAuthenticated = await flutterFeathersjs.scketio.authWithJWT();
53+
54+
//print(isReAuthenticated); => true
55+
56+
} on FeatherJsError catch (e) {
57+
if (e.type == FeatherJsErrorType.IS_JWT_TOKEN_ERROR) {
58+
//TODO: Error using the JWT to authenticated
59+
// Redirect user to login page
60+
}else{
61+
//TODO: Check for other FeatherJsErrorType
62+
// why => print(e.type);
63+
// why => print(e.message);
64+
}
65+
} catch (e) {
66+
//TODO: Authentication failed for unkknown reason.
67+
// why => print(e.type);
68+
// why => print(e.message);
69+
}
4170
4271
```
4372

73+
## Global (recommended)
4474

75+
### Autenticate
4576

46-
## Global Auth (recommanded)
47-
48-
Definitely, this is what you must do when you want to authenticate your user.
77+
Go to login page, retrieve user credentials and authenticat user
78+
with different strategy
4979

5080
```dart
81+
try {
5182
52-
/// ------ First time
83+
// Default strategy (email/password => local strategy)
84+
var user = await flutterFeathersjs.authenticate(
85+
userName: "dah.kenangnon@flutter_feathersjs.com",
86+
password: "flutter_feathersjs");
5387
54-
// Auth globaly with phone number strategy
55-
// When using this strategy: ensure you configure your feathers js server accordingly
56-
var rep = await flutterFeathersjs.authenticate(
88+
// Or use what you want, e.g: phone/password
89+
// Auth with rest client with phone/password strategy
90+
// Note: You must configure your server for this strategy to work
91+
var user = await flutterFeathersjs.authenticate(
5792
strategy: "phone",
58-
userNameFieldName: "tel",
59-
userName: "+22900000000",
60-
password: "Strong_Pass");
61-
62-
63-
64-
65-
// Auth globaly with email strategy [default]
66-
var rep = await flutterFeathersjs.authenticate(
67-
userName: "mail@mail.com",
68-
password: "Strong_Pass");
69-
70-
/// ------ On app restart or when JWT still validated
71-
var reps = await flutterFeathersjs.reAuthenticate();
72-
73-
if (!reps["error"]) {
74-
print('client is authed');
75-
print("----------Authed user :------");
76-
print(reps["message"]); // User is under reps["message"] when all thing is Ok
77-
print("----------Authed user :------");
78-
} else
79-
{
80-
print(reps["message"]); // Error message is under reps["message"] when something is wrong
93+
userNameFieldName: "tel", // "tel" is the fieldname on the mongoose|? model
94+
userName:"+22900000000",
95+
password: "flutter_feathersjs");
96+
97+
98+
//TODO: Authentication is Ok, save user in local storage
99+
100+
} on FeatherJsError catch (e) {
101+
if (e.type == FeatherJsErrorType.IS_INVALID_CREDENTIALS_ERROR) {
102+
//TODO: Invalid credentials
103+
} else if (e.type == FeatherJsErrorType.IS_INVALID_STRATEGY_ERROR) {
104+
//TODO: Invalid strategy
105+
} else if (e.type == FeatherJsErrorType.IS_AUTH_FAILED_ERROR) {
106+
//TODO: Invalid authentication failed for other reason.
107+
// verbose => print(e.message);
108+
}
109+
//TODO: Check for other FeatherJsErrorType
110+
// => print(e.type);
111+
} catch (e) {
112+
//TODO: Authentication failed for unkknown reason.
113+
// why => print(e.type);
114+
// why => print(e.message);
115+
}
116+
```
81117

82-
// If you want to check when error is comming from socketio client
83-
// Error message from socketio client,
84-
print(reps["scketResponse"]);
118+
## ReAuthenticate on app restarted
85119

120+
Then reAutenticate user, if JWT still validated without request credentials from user on app restart
86121

87-
// If you want to check when error is comming from rest client
88-
// Error message from rest client,
89-
print(reps["restResponse"]);
122+
```dart
123+
try {
124+
bool isReAuthenticated = await flutterFeathersjs.reAuthenticate();
125+
126+
//print(isReAuthenticated); => true
127+
128+
} on FeatherJsError catch (e) {
129+
if (e.type == FeatherJsErrorType.IS_AUTH_FAILED_ERROR) {
130+
//TODO: ReAutentication failed
131+
// Redirect user to login page
132+
}else{
133+
//TODO: Check for other FeatherJsErrorType
134+
// why => print(e.type);
135+
// why => print(e.message);
136+
}
137+
} catch (e) {
138+
//TODO: Authentication failed for unkknown reason.
139+
// why => print(e.type);
140+
// why => print(e.message);
90141
}
91-
```
142+
```

docs/src/guide/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Examples
22

3-
Coming soon.
3+
[Please see demo link in the introduction page](README.md#demo)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Uploading file with FlutterFeathersJs
22

3-
Coming soon.
3+
If you need to upload file, you should only do this with FlutterFeathersJs's rest client
4+
5+
[Using rest client to upload file](using-rest.md#create)

docs/src/guide/installation.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ flutter_feathersjs: ^lastest
1010
## Import it in your flutter code
1111
1212
```dart
13-
13+
// Main package
1414
import 'package:flutter_feathersjs/flutter_feathersjs.dart';
15+
// Contains helper like error handling, etc..
16+
import 'package:flutter_feathersjs/src/helper.dart';
1517

1618
```
1719

@@ -21,11 +23,12 @@ import 'package:flutter_feathersjs/flutter_feathersjs.dart';
2123
2224
2325
//your api
24-
const BASE_URL = "https://api.my-featherjs-domain.com";
26+
const BASE_URL = "https://flutter-feathersjs.herokuapp.com";
2527
28+
// Init it globally accross your app, maybe with get_it
2629
FlutterFeathersjs flutterFeathersjs = FlutterFeathersjs()
2730
..init(baseUrl: BASE_URL);
2831
2932
```
3033

31-
You're ready to go
34+
You're ready to go :rocket:

docs/src/guide/listening-event.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Realtime with FlutterFeatherJs
22

3-
Coming soon.
3+
You can listen to feathers js realtime event with scketio client
4+
5+
[Listen to realtime event with scketio client](using-socketio.html#listen)

0 commit comments

Comments
 (0)