Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmailPasswordAuth renames #3048

Merged
merged 4 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ NOTE: This version bumps the Realm file format to version 11. It is not possible
* `Realm.Auth.UserAPIKeyProvider` has been replaced by `Realm.Auth.ApiKeyProvider`.
* `user.auth.apiKeys` has been replaced by `user.apiKeys`.
* The instance methods on the ApiKeyAuth instance (`user.apiKeys`) have gotten their APIKey(s) suffix removed: Ex. `apiKeys.createAPIKey` has been replaced by `apiKeys.create`.
* `Realm.Auth.EmailPasswordProvider` has been replaced by `Realm.Auth.EmailPasswordAuth`.
* `app.auth.emailPassword` has been replaced by `user.emailPasswordAuth`.

### Enhancements
* None.
Expand Down
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"src/js_app_credentials.hpp",
"src/js_user.hpp",
"src/js_network_transport.hpp",
"src/js_email_password_provider.hpp",
"src/js_email_password_auth.hpp",
"src/node/sync_logger.cpp",
"src/node/sync_logger.hpp",
]
Expand Down
18 changes: 9 additions & 9 deletions docs/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,18 @@
removeUser(user) { }

/**
* Auth providers. Currently only `emailPassword` provider is support
* Client for the email/password authentication provider.
*
* @example
* {
* let app = new Realm.App(config);
* let provider = app.auth.emailPassword;
* // Creating a new user, by registering via email & password
* const app = new Realm.App(config);
* await app.emailPasswordAuth.registerEmail('john@example.com', 'some-secure-password');
* }
*
* @see Realm.Auth
* @see Realm.Auth.EmailPassword
* @type {Realm.Auth.EmailPasswordAuth}
*/
get auth() { }
get emailPasswordAuth() { }
}


Expand Down Expand Up @@ -351,8 +351,8 @@ class Credentials {

/**
* A namespace for auth providers
* @see Realm.Auth.EmailPassword
* @see Realm.Auth.UserAPIKey
* @see Realm.Auth.EmailPasswordAuth
* @see Realm.Auth.ApiKeyAuth
* @memberof Realm
*/
class Auth {
Expand All @@ -363,7 +363,7 @@ class Auth {
* Class for managing email/password for users
* @memberof Realm.Auth
*/
class EmailPassword {
class EmailPasswordAuth {

/**
* Registers a new email identity with the username/password provider,
Expand Down
11 changes: 0 additions & 11 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ const instanceMethods = {
removeUser() {
return promisify(cb => this._removeUser(cb));
},

get auth() {
const app = this;
return new Proxy({}, {
get(target, name) {
if (name === "emailPassword") {
return app._authEmailPassword;
}
}
});
}
};

const staticMethods = {
Expand Down
100 changes: 50 additions & 50 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
//
////////////////////////////////////////////////////////////////////////////

'use strict';
"use strict";

/* global navigator */

const URL = require('url-parse');
const URL = require("url-parse");

let getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function(obj) {
return Object.getOwnPropertyNames(obj).reduce(function (descriptors, name) {
Expand All @@ -31,7 +31,7 @@ let getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function(obj

function setConstructorOnPrototype(klass) {
if (klass.prototype.constructor !== klass) {
Object.defineProperty(klass.prototype, 'constructor', { value: klass, configurable: true, writable: true });
Object.defineProperty(klass.prototype, "constructor", { value: klass, configurable: true, writable: true });
}
}

Expand Down Expand Up @@ -67,17 +67,17 @@ function openLocalRealm(realmConstructor, config) {

module.exports = function(realmConstructor, context) {
// Add the specified Array methods to the Collection prototype.
Object.defineProperties(realmConstructor.Collection.prototype, require('./collection-methods'));
Object.defineProperties(realmConstructor.Collection.prototype, require("./collection-methods"));

setConstructorOnPrototype(realmConstructor.Collection);
setConstructorOnPrototype(realmConstructor.List);
setConstructorOnPrototype(realmConstructor.Results);
setConstructorOnPrototype(realmConstructor.Object);

realmConstructor._bson = require('bson');
realmConstructor._bson = require("bson");
realmConstructor._Decimal128 = realmConstructor._bson.Decimal128;
realmConstructor._ObjectId = realmConstructor._bson.ObjectId;
const { DefaultNetworkTransport } = require('realm-network-transport');
const { DefaultNetworkTransport } = require("realm-network-transport");
realmConstructor._networkTransport = new DefaultNetworkTransport();

Object.defineProperty(realmConstructor.Object.prototype, "toJSON", {
Expand Down Expand Up @@ -139,10 +139,10 @@ module.exports = function(realmConstructor, context) {
if (config.sync[behavior] !== undefined) {
const type = config.sync[behavior].type;
switch (type) {
case 'downloadBeforeOpen':
case "downloadBeforeOpen":
openLocalRealmImmediately = false;
break;
case 'openImmediately':
case "openImmediately":
openLocalRealmImmediately = true;
break;
default:
Expand All @@ -162,7 +162,7 @@ module.exports = function(realmConstructor, context) {
let openPromises = [];
if (config.sync[behavior] !== undefined && config.sync[behavior].timeOut !== undefined) {
let timeOut = config.sync[behavior].timeOut;
if (typeof timeOut !== 'number') {
if (typeof timeOut !== "number") {
throw new Error(`'timeOut' must be a number: '${timeOut}'`);
}

Expand All @@ -171,10 +171,10 @@ module.exports = function(realmConstructor, context) {
if (config.sync[behavior] !== undefined && config.sync[behavior].timeOutBehavior) {
const timeOutBehavior = config.sync[behavior].timeOutBehavior;
switch (timeOutBehavior) {
case 'throwException':
case "throwException":
throwOnTimeOut = true;
break;
case 'openLocal':
case "openLocal":
throwOnTimeOut = false;
break;
default:
Expand Down Expand Up @@ -241,7 +241,7 @@ module.exports = function(realmConstructor, context) {
for (let key in objectSchema.properties) {

let type;
if (typeof objectSchema.properties[key] === 'string' || objectSchema.properties[key] instanceof String) {
if (typeof objectSchema.properties[key] === "string" || objectSchema.properties[key] instanceof String) {
// Simple declaration of the type
type = objectSchema.properties[key];
} else {
Expand All @@ -265,13 +265,13 @@ module.exports = function(realmConstructor, context) {
// Set the default value for all required primitive types.
// Lists are always treated as empty if not specified and references to objects are always optional
switch (type) {
case 'bool': obj[key] = false; break;
case 'int': obj[key] = 0; break;
case 'float': obj[key] = 0.0; break;
case 'double': obj[key] = 0.0; break;
case 'string': obj[key] = ""; break;
case 'data': obj[key] = new ArrayBuffer(0); break;
case 'date': obj[key] = new Date(0); break;
case "bool": obj[key] = false; break;
case "int": obj[key] = 0; break;
case "float": obj[key] = 0.0; break;
case "double": obj[key] = 0.0; break;
case "string": obj[key] = ""; break;
case "data": obj[key] = new ArrayBuffer(0); break;
case "date": obj[key] = new Date(0); break;
}
}
return obj;
Expand All @@ -287,7 +287,7 @@ module.exports = function(realmConstructor, context) {
schemas.forEach(schema => {
// a schema must be an object and have 'name' and 'properties'
// we let object store's schema parser produce the error messages
if (!(schema instanceof Object) || !schema.hasOwnProperty('name') || !schema.hasOwnProperty('properties')) {
if (!(schema instanceof Object) || !schema.hasOwnProperty("name") || !schema.hasOwnProperty("properties")) {
newSchema.push(schema);
return;
}
Expand All @@ -314,13 +314,13 @@ module.exports = function(realmConstructor, context) {
os.properties = {};
for (let key in schema.properties) {
let prop = schema.properties[key];
if (prop instanceof Object && prop.hasOwnProperty('name') && prop.hasOwnProperty('properties')) {
if (prop instanceof Object && prop.hasOwnProperty("name") && prop.hasOwnProperty("properties")) {
let embeddedSchema = {};
embeddedSchema.name = prop.name;
embeddedSchema.embedded = true;
embeddedSchema.properties = prop.properties;
if (prop.hasOwnProperty('type') && prop.type === 'list') {
os.properties[key] = { type: 'list', objectType: prop.name };
if (prop.hasOwnProperty("type") && prop.type === "list") {
os.properties[key] = { type: "list", objectType: prop.name };
} else {
os.properties[key] = { type: prop.name };
}
Expand All @@ -338,13 +338,13 @@ module.exports = function(realmConstructor, context) {

// Add static properties to Realm Object
const updateModeType = {
All: 'all',
Modified: 'modified',
Never: 'never',
All: "all",
Modified: "modified",
Never: "never",
};

if (!realmConstructor.UpdateMode) {
Object.defineProperty(realmConstructor, 'UpdateMode', {
Object.defineProperty(realmConstructor, "UpdateMode", {
value: updateModeType,
configurable: false,
});
Expand All @@ -363,8 +363,8 @@ module.exports = function(realmConstructor, context) {
let credentialMethods = require("./credentials");
Object.defineProperties(realmConstructor.Credentials, getOwnPropertyDescriptors(credentialMethods.static))

let emailPasswordProviderMethods = require("./email_password_provider_client_methods");
Object.defineProperties(realmConstructor.Auth.EmailPasswordProvider.prototype, getOwnPropertyDescriptors(emailPasswordProviderMethods.instance));
let emailPasswordAuthMethods = require("./email_password_provider_client_methods");
Object.defineProperties(realmConstructor.Auth.EmailPasswordAuth.prototype, getOwnPropertyDescriptors(emailPasswordAuthMethods.instance));

let apiKeyAuthMethods = require("./user_apikey_provider_client");
Object.defineProperties(realmConstructor.Auth.ApiKeyAuth.prototype, getOwnPropertyDescriptors(apiKeyAuthMethods.instance));
Expand Down Expand Up @@ -393,13 +393,13 @@ module.exports = function(realmConstructor, context) {


realmConstructor.Sync.openLocalRealmBehavior = {
type: 'openImmediately'
type: "openImmediately"
};

realmConstructor.Sync.downloadBeforeOpenBehavior = {
type: 'downloadBeforeOpen',
type: "downloadBeforeOpen",
timeOut: 30 * 1000,
timeOutBehavior: 'throwException'
timeOutBehavior: "throwException"
};
realmConstructor.Sync.Session.prototype.uploadAllLocalChanges = function(timeout) {
return waitForCompletion(this, this._waitForUploadCompletion, timeout, `Uploading changes did not complete in ${timeout} ms.`);
Expand All @@ -416,9 +416,9 @@ module.exports = function(realmConstructor, context) {
};

realmConstructor.Sync.ClientResyncMode = {
Discard: 'discard',
Manual: 'manual',
Recover: 'recover'
Discard: "discard",
Manual: "manual",
Recover: "recover"
};

Object.defineProperties(realmConstructor, getOwnPropertyDescriptors({
Expand All @@ -429,10 +429,10 @@ module.exports = function(realmConstructor, context) {
// Credit: https://stackoverflow.com/questions/39468022/how-do-i-know-if-my-code-is-running-as-react-native
try {
var userAgent = "RealmJS/";
userAgent = userAgent + require('../package.json').version + " (" + context + ", ";
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
userAgent = userAgent + require("../package.json").version + " (" + context + ", ";
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
// Running on ReactNative
const Platform = require('react-native').Platform;
const Platform = require("react-native").Platform;
userAgent += Platform.OS + ", v" + Platform.Version;
} else {
// Running on a normal machine
Expand All @@ -448,23 +448,23 @@ module.exports = function(realmConstructor, context) {

// TODO: Remove this now useless object.
var types = Object.freeze({
'BOOL': 'bool',
'INT': 'int',
'FLOAT': 'float',
'DOUBLE': 'double',
'STRING': 'string',
'DATE': 'date',
'DATA': 'data',
'OBJECT': 'object',
'LIST': 'list',
"BOOL": "bool",
"INT": "int",
"FLOAT": "float",
"DOUBLE": "double",
"STRING": "string",
"DATE": "date",
"DATA": "data",
"OBJECT": "object",
"LIST": "list",
});
Object.defineProperty(realmConstructor, 'Types', {
Object.defineProperty(realmConstructor, "Types", {
get: function() {
if (typeof console != 'undefined') {
if (typeof console != "undefined") {
/* global console */
/* eslint-disable no-console */
var stack = new Error().stack.split("\n").slice(2).join("\n");
var msg = '`Realm.Types` is deprecated! Please specify the type name as lowercase string instead!\n'+stack;
var msg = "`Realm.Types` is deprecated! Please specify the type name as lowercase string instead!\n"+stack;
if (console.warn != undefined) {
console.warn(msg);
}
Expand Down
4 changes: 2 additions & 2 deletions src/RealmJS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
3FCE2A991F58BE3600D4855B /* feature_checks.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = feature_checks.hpp; path = "object-store/src/feature_checks.hpp"; sourceTree = SOURCE_ROOT; };
42BD57A824640A94008679D5 /* js_app.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_app.hpp; sourceTree = "<group>"; };
42BD57A924640A94008679D5 /* js_app_credentials.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_app_credentials.hpp; sourceTree = "<group>"; };
42BD57AA24640A94008679D5 /* js_email_password_provider.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_email_password_provider.hpp; sourceTree = "<group>"; };
42BD57AA24640A94008679D5 /* js_email_password_auth.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_email_password_auth.hpp; sourceTree = "<group>"; };
42BD57AB24640A94008679D5 /* js_user.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_user.hpp; sourceTree = "<group>"; };
42BD57AC24640A94008679D5 /* js_network_transport.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_network_transport.hpp; sourceTree = "<group>"; };
42BD57AD24640A95008679D5 /* js_sync_util.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = js_sync_util.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -362,7 +362,7 @@
42BD57AD24640A95008679D5 /* js_sync_util.hpp */,
42BD57AE24640A95008679D5 /* js_api_key_auth.hpp */,
42BD57AB24640A94008679D5 /* js_user.hpp */,
42BD57AA24640A94008679D5 /* js_email_password_provider.hpp */,
42BD57AA24640A94008679D5 /* js_email_password_auth.hpp */,
F62A35131C18E6E2004A917D /* iOS */,
F6874A441CAD2ACD00EEEE36 /* JSC */,
F6BCCFDF1C83809A00FE31AE /* lib */,
Expand Down
10 changes: 5 additions & 5 deletions src/js_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "js_user.hpp"
#include "js_app_credentials.hpp"
#include "js_network_transport.hpp"
#include "js_email_password_provider.hpp"
#include "js_email_password_auth.hpp"

using SharedApp = std::shared_ptr<realm::app::App>;
using SharedUser = std::shared_ptr<realm::SyncUser>;
Expand Down Expand Up @@ -60,11 +60,11 @@ class AppClass : public ClassDefinition<T, SharedApp> {
static FunctionType create_constructor(ContextType);

static void get_app_id(ContextType, ObjectType, ReturnValue &);
static void get_auth_email_password(ContextType, ObjectType, ReturnValue &);
static void get_email_password_auth(ContextType, ObjectType, ReturnValue &);

PropertyMap<T> const properties = {
{"id", {wrap<get_app_id>, nullptr}},
{"_authEmailPassword", {wrap<get_auth_email_password>, nullptr}},
{"emailPasswordAuth", {wrap<get_email_password_auth>, nullptr}},
};

static void login(ContextType, ObjectType, Arguments&, ReturnValue&);
Expand Down Expand Up @@ -296,9 +296,9 @@ void AppClass<T>::remove_user(ContextType ctx, ObjectType this_object, Arguments
}

template<typename T>
void AppClass<T>::get_auth_email_password(ContextType ctx, ObjectType this_object, ReturnValue &return_value) {
void AppClass<T>::get_email_password_auth(ContextType ctx, ObjectType this_object, ReturnValue &return_value) {
auto app = *get_internal<T, AppClass<T>>(ctx, this_object);
return_value.set(EmailPasswordProviderClientClass<T>::create_instance(ctx, app));
return_value.set(EmailPasswordAuthClass<T>::create_instance(ctx, app));
}

}
Expand Down
Loading