I'm running out of time to work on the package. Pull requests are welcome!
Carefully extended meteorify package to interact with the Meteor framework.
Connect your web or flutter apps, written in Dart, to the Meteor framework.
- Connect to Meteor server
- Use Meteor Subscriptions
- Meteor Authentication
- oAuth Authentication with Google, Facebook and Apple* (needs server-side code in JavaScript for use with Meteor)
- Call custom Methods on Meteor
- Access underlying databases
*Login with Apple currently only supports iOS 13+.
Add this to your package's pubspec.yaml
file:
dependencies:
enhanced_meteorify: ^2.3.4
Null safety:
dependencies:
enhanced_meteorify: ^3.1.0
You can use the await
syntax to capture the result of operations and handle errors.
I'll be using the await
syntax in this documentation to keep it short and straight.
import 'package:meteorify/meteorify.dart';
main() async{
try{
var status = await Meteor.connect('ws://example.meteor.com/websocket', );
// Do something after connection is successful
}catch(error){
print(error);
//Handle error
}
}
var isConnected = Meteor.isConnected;
Meteor.disconnect();
Meteor.connectionListener = (ConnectionStatus connectionStatus) {
print(connectionStatus);
}
Meteor.currentUserIdListener = (String userId) {
print(userId);
}
var subscriptionId = await Meteor.subscribe(subscriptionName);
var subscriptionId = await Meteor.subscribe(subscriptionName,args:[arg1,arg2]);
await Meteor.unsubscribe(subscriptionId);
SubscribedCollection collection = await Meteor.collection(collectionName);
//collection.find({selectors});
//collection.findAll();
//collection.findOne(id);
var userId = await Meteor.createUser(username, email, password, profileOptions);
-
Login with password
// Login with email try { String loginToken = await Meteor.loginWithPassword(email, password); } catch(error) { print(error); } // Login with username try { String loginToken = await Meteor.loginWithPassword(username, password); } catch(error) { print(error); }
-
Login with token
try { String token = await Meteor.loginWithToken(loginToken); } catch(error) { print(error); }
-
Login with Google
// `email` to register with. Must be fetched from the Google oAuth API // The unique Google `userId`. Must be fetched from the Google oAuth API // `authHeaders` from Google oAuth API for server side validation try { String token = await Meteor.loginWithGoogle(email, userId, authHeaders) } catch(error) { print(error); }
Install google_sing_in package
dependencies: flutter: sdk: flutter google_sign_in: ^4.4.4
import 'package:google_sign_in/google_sign_in.dart'; GoogleSignIn _googleSignIn = GoogleSignIn( scopes: ['profile', 'email', 'openid'], ); Future<void> _loginWithGoogle(context) async { try { var info = await _googleSignIn.signIn(); var authHeaders = await info.authHeaders; var result = await Meteor.loginWithGoogle(info.email, info.id, authHeaders); print(result); } catch (error) { print(error); } }
-
Login with Facebook
// [userId] the unique Facebook userId. Must be fetched from the Facebook Login API // [token] the token from Facebook API Login for server side validation try { String token = await Meteor.loginWithFacebook(userId, token) } catch(error) { print(error); }
Install flutter_facebook_login package
dependencies: flutter: sdk: flutter flutter_facebook_login: ^3.0.0
import 'package:flutter_facebook_login/flutter_facebook_login.dart'; Future<void> _loginWithFacebook(context) async { final result = await facebookLogin.logIn(['email, public_profile']); switch (result.status) { case FacebookLoginStatus.loggedIn: var userId = result.accessToken.userId; var token = result.accessToken.userId; var res = await Meteor.loginWithFacebook(userId, token); print(res); break; case FacebookLoginStatus.cancelledByUser: print(':/'); break; case FacebookLoginStatus.error: print('error: ${result.errorMessage}'); break; } }
-
Login with Apple
// [userId] the unique Apple userId. Must be fetch from the Apple Login API // [jwt] the jwt from Apple API Login to get user's e-mail // [givenName] user's given Name. Must be fetched from the Apple Login API // [lastName] user's last Name. Must be fetched from the Apple Login API try { String token = await Meteor.loginWithApple(userId, jwt, givenName, lastName) } catch(error) { print(error); }
Install apple_sign_in package
dependencies: flutter: sdk: flutter apple_sign_in: ^0.1.0
import 'package:apple_sign_in/apple_sign_in.dart';
Future<void> _loginWithApple(context) async {
try {
final AuthorizationResult result = await AppleSignIn.performRequests([
AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
]);
switch (result.status) {
case AuthorizationStatus.authorized:
var userId = result.credential.user;
var jwt = result.credential.identityToken;
var givenName = result.credential.fullName.givenName;
var lastName = result.credential.fullName.familyName;
var res = await Meteor.loginWithApple(userId, jwt, givenName, lastName);
print(res);
break;
case AuthorizationStatus.error:
print('Erro: ${result.error.localizedDescription}');
break;
case AuthorizationStatus.cancelled:
print(':/');
break;
}
} catch (error) {
print(error);
}
}
-
Change Password (need to be logged in)
bool result = await Meteor.changePassword(oldPassword, newPassword);
-
Forgot Password
bool result = await Meteor.forgotPassword(email);
-
Reset Password
bool result = await Meteor.resetPassword(resetToken, newPassword);
-
Logout
await Meteor.logout();
- Get logged in userId
String userId = Meteor.currentUserId;
- Check if logged in
bool isLoggedIn = Meteor.isLoggedIn();
- Get current user as map
Map<String,dynamic> currentUser = await Meteor.userAsMap();
export const helloWorld = new ValidatedMethod({
name: 'hello',
validate: new SimpleSchema({
firstname: {type: String},
lastname: {type: String},
}).validator(),
run({ firstname,lastname }) {
const message = "hello "+ firstname + " " + lastname;
console.log(message);
return message;
},
});
try{
var result = await Meteor.call('hello',[{'firstname':'Wendell','lastname':'Rocha'}]);
print(result);
}catch(error){
print(error);
}