Skip to content

Commit 5ffb3cd

Browse files
committed
Add event listen, document code, support other auth strategy, ...
1 parent 8c9ff12 commit 5ffb3cd

File tree

13 files changed

+642
-259
lines changed

13 files changed

+642
-259
lines changed

CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
## 0.0.7
21

2+
## 0.1.0
33

4-
## 0.0.1+1
4+
- Improvment: Documentation of the code
5+
- Breaking: on both rest and socketio, you get exactly what feathers js send, we don't support any serializer or deserializer. So how previous version handle data is breaken
6+
- Feature: Add event listen but not fully tested
7+
- Authentication don't matter if you auth user with email/password. You can use email/password, phone/password, userName/password
8+
- Feature: support now phone, email, etc, with password authentication
59

6-
- remove unsed comment
7-
## 0.0.1
10+
## 0.0.7
811

12+
- remove unused comment
913
- Add formData handling
1014
- Update readme
15+
1116
## 0.0.6-dev
1217

1318
- Fix

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The MIT License (MIT)
22

3-
Copyright (c) 2019 Justin Dah-kenangnon <dah.kenangnon@gmail.com>
3+
Copyright (c) 2020-present Justin Dah-kenangnon <dah.kenangnon@gmail.com>
44

55
> Permission is hereby granted, free of charge, to any person obtaining a copy
66
> of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# flutter_feathersjs :bird:
1+
# :bird: flutter_feathersjs :bird:
22

3-
Communicate with your feathers js server from flutter.
4-
*__FormData support out the box, auth, reAuth, socketio send event, rest ...__ But event listen via socketio not yet implemented*
3+
Communicate with your feathers js (https://feathersjs.com/) server from flutter.
54

5+
`Infos: Feathers js is a node framework for real-time applications and REST APIs.`
6+
7+
8+
*__FormData support out the box, auth, reAuth, socketio send event, rest ...__
69

710
## Import it
811

@@ -22,34 +25,44 @@ FlutterFeathersjs flutterFeathersjs = FlutterFeathersjs()
2225
## Authentication with either with rest or socketio
2326

2427
```dart
25-
// Auth with rest client
28+
// Auth with rest client with email/password [Default strategy is email/password]
2629
var authResponse = await flutterFeathersjs.rest
27-
.authenticate(email: user["email"], password: user["password"]);
30+
.authenticate(userName: user["email"], password: user["password"]);
31+
32+
// Auth with rest client with phone/password
33+
var authResponse = await flutterFeathersjs.rest.authenticate(
34+
strategy: "phone",
35+
userNameFieldName: "tel",
36+
userName: user["tel"],
37+
password: user["password"]);
2838
2939
//Second time, application will restart, just:
3040
var reAuthResponse = await flutterFeathersjs.rest.reAuthenticate();
3141
3242
// Or With socketio
3343
// Note: This must be call after rest auth success
44+
// Not recommanded to use this directly
3445
var authResponse = await flutterFeathersjs.scketio.authWithJWT();
3546
3647
```
3748

38-
## Simplify yor life, Auth both client one time
49+
## Auth both client one time
3950

4051
```dart
4152
4253
// Auth first time with credentials
43-
var authResponse = await flutterFeathersjs.authenticate(email: null, password: null);
54+
var authResponse = await flutterFeathersjs.authenticate(
55+
strategy: "phone",
56+
userNameFieldName: "tel",
57+
userName: user["tel"],
58+
password: user["password"]);
4459
4560
// on App restart, don't disturbe user, just reAuth with with accessToken, early store by FlutterFeathersjs
4661
var reAuthResponse = await flutterFeathersjs.reAuthenticate()
4762
4863
```
4964

50-
## Important
65+
## Contribution
5166

52-
- Listen to event on socketio is not yet implemented
53-
- Documentation is coming
5467
- Contact-me for improvment or contribution purpose
5568
- Example is coming

example/pubspec.lock

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ packages:
5757
url: "https://pub.dartlang.org"
5858
source: hosted
5959
version: "3.0.10"
60+
event_bus:
61+
dependency: transitive
62+
description:
63+
name: event_bus
64+
url: "https://pub.dartlang.org"
65+
source: hosted
66+
version: "1.1.1"
6067
fake_async:
6168
dependency: transitive
6269
description:
@@ -86,10 +93,10 @@ packages:
8693
flutter_feathersjs:
8794
dependency: "direct main"
8895
description:
89-
name: flutter_feathersjs
90-
url: "https://pub.dartlang.org"
91-
source: hosted
92-
version: "0.0.6-dev"
96+
path: ".."
97+
relative: true
98+
source: path
99+
version: "0.1.0"
93100
flutter_test:
94101
dependency: "direct dev"
95102
description: flutter

example/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13-
flutter_feathersjs: ^0.0.7
13+
flutter_feathersjs:
14+
path: ../
1415
cupertino_icons: ^1.0.0
1516

1617
dev_dependencies:

lib/flutter_feathersjs.dart

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,44 @@
1+
/// Communicate with your feathers js (https://feathersjs.com/) server from flutter app.
12
library flutter_feathersjs;
23

34
import 'package:flutter_feathersjs/src/constants.dart';
45
import 'package:flutter_feathersjs/src/rest_client.dart';
56
import 'package:flutter_feathersjs/src/scketio_client.dart';
67
import 'package:meta/meta.dart';
8+
//import 'package:flutter/foundation.dart' as Foundation;
79

8-
/// FlutterFeatherJs allow you to communicate with your feathers js server
10+
///
11+
///FlutterFeatherJs allow you to communicate with your feathers js server
12+
///
13+
///_______________________________________________
14+
///_______________________________________________
15+
///
16+
///
17+
/// `GENERAL NOTE 1`: Serialization and Deserialization are not supported.
18+
///
19+
/// You get exactly what feathers server send
20+
///
21+
/// `GENERAL NOTE 2`: To send file, use rest client, socketio client cannot upload file
22+
///
23+
/// Authentification is processed by:
24+
///
25+
/// // Global auth (Rest and Socketio)
26+
/// var rep = await flutterFeathersjs
27+
/// .authenticate(userName: user["email"], password: user["password"]);
28+
///
29+
/// //Then use this one to reUse access token as it still valided
30+
/// var reAuthResp = await flutterFeathersjs.reAuthenticate();
31+
///
32+
///
933
class FlutterFeathersjs {
1034
//RestClient
1135
RestClient rest;
1236
//SocketioClient
1337
SocketioClient scketio;
1438

39+
// For debug purpose
40+
bool dev = false;
41+
1542
///Using singleton
1643
static final FlutterFeathersjs _flutterFeathersjs =
1744
FlutterFeathersjs._internal();
@@ -22,13 +49,32 @@ class FlutterFeathersjs {
2249

2350
///Intialize both rest and scoketio client
2451
init({@required String baseUrl, Map<String, dynamic> extraHeaders}) {
52+
// if (Foundation.kReleaseMode) {
53+
// // W're on release mode
54+
// dev = false;
55+
// } else {
56+
// // W're not on release mode
57+
// dev = true;
58+
// }
59+
2560
rest = new RestClient()..init(baseUrl: baseUrl, extraHeaders: extraHeaders);
61+
2662
scketio = new SocketioClient()..init(baseUrl: baseUrl);
2763
}
2864

2965
/// Authenticate rest and scketio clients so you can use both of them
66+
///
67+
///___________________________________________________________________
68+
/// @params `username` can be : email, phone, etc;
69+
///
70+
/// But ensure that `userNameFieldName` is correct with your chosed `strategy`
71+
///
72+
/// By default this will be `email`and the strategy `local`
3073
Future<Map<String, dynamic>> authenticate(
31-
{@required String email, @required String password}) async {
74+
{String strategy = "local",
75+
@required String userName,
76+
@required String password,
77+
String userNameFieldName = "email"}) async {
3278
//Hold global auth infos
3379
Map<String, dynamic> authResponse = {
3480
"error": true,
@@ -39,8 +85,11 @@ class FlutterFeathersjs {
3985
};
4086

4187
//Auth with rest to refresh or create accessToken
42-
Map<String, dynamic> restAuthResponse =
43-
await rest.authenticate(email: email, password: password);
88+
Map<String, dynamic> restAuthResponse = await rest.authenticate(
89+
strategy: strategy,
90+
userName: userName,
91+
userNameFieldName: userNameFieldName,
92+
password: password);
4493
//Then auth with jwt socketio
4594
Map<String, dynamic> socketioAuthResponse = await scketio.authWithJWT();
4695

@@ -55,6 +104,8 @@ class FlutterFeathersjs {
55104
}
56105

57106
/// Authenticate rest and scketio clients so you can use both of them
107+
///
108+
///___________________________________________________________________
58109
Future<Map<String, dynamic>> reAuthenticate() async {
59110
//Hold global auth infos
60111
Map<String, dynamic> authResponse = {

lib/src/constants.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,9 @@ class Constants {
1414
static const String BOTH_CLIENT_AUTHED = "BOTH_CLIENT_AUTHED";
1515
static const String ONE_OR_BOTH_CLIENT_NOT_AUTHED =
1616
"ONE_OR_BOTH_CLIENT_NOT_AUTHED";
17+
static const String FEATHERSJS_ACCESS_TOKEN = "FEATHERSJS_ACCESS_TOKEN";
1718
}
1819

19-
class Removed<T> {}
20-
21-
class Patched<T> {}
22-
23-
class Created<T> {}
24-
25-
class Updated<T> {}
26-
2720
class Connected {}
2821

2922
class DisConnected {}

0 commit comments

Comments
 (0)