@stanlemon/react-couchdb-authentication
Advanced tools
Comparing version 0.4.0 to 0.4.1
# Changelog | ||
## 4.0.0 (July 12, 2020) | ||
## 4.0.1 (July 12, 2020) | ||
@@ -5,0 +5,0 @@ * `<Login />` and `<SignUp />` no longer require properties other than `component`, making them easier to use in contexts where `scaffold` is set to `false`. |
@@ -24,7 +24,7 @@ "use strict"; | ||
const React = __importStar(require("react")); | ||
const __1 = require("../"); | ||
const Authentication_1 = require("./Authentication"); | ||
function Authenticated({ children, }) { | ||
return (React.createElement(__1.Context.Consumer, null, ({ authenticated }) => authenticated ? children : null)); | ||
return (React.createElement(Authentication_1.Context.Consumer, null, ({ authenticated }) => authenticated ? children : null)); | ||
} | ||
exports.Authenticated = Authenticated; | ||
//# sourceMappingURL=Authenticated.js.map |
@@ -26,15 +26,7 @@ import * as React from "react"; | ||
*/ | ||
login: React.ReactElement<{ | ||
error: string; | ||
login(username: string, password: string): void; | ||
navigateToSignUp(): void; | ||
}>; | ||
login: React.ReactElement; | ||
/** | ||
* A component to be used for the signup screen. | ||
*/ | ||
signup: React.ReactElement<{ | ||
error: string; | ||
signUp(username: string, password: string, email: string): void; | ||
navigateToLogin(): void; | ||
}>; | ||
signup: React.ReactElement; | ||
/** | ||
@@ -115,4 +107,5 @@ * A component to be used when loading, defaults to a fragment with the text "Loading...". | ||
render(): React.ReactNode; | ||
private renderChildren; | ||
} | ||
export {}; | ||
//# sourceMappingURL=Authentication.d.ts.map |
@@ -43,3 +43,6 @@ "use strict"; | ||
const async_retry_1 = __importDefault(require("async-retry")); | ||
const __1 = require("../"); | ||
const Login_1 = require("./Login"); | ||
const LoginView_1 = require("./LoginView"); | ||
const SignUp_1 = require("./SignUp"); | ||
const SignUpView_1 = require("./SignUpView"); | ||
const ROUTE_LOGIN = "login"; | ||
@@ -285,3 +288,5 @@ const ROUTE_SIGNUP = "signup"; | ||
} | ||
await __classPrivateFieldGet(this, _remoteDb).close(); | ||
if (__classPrivateFieldGet(this, _remoteDb)) { | ||
await __classPrivateFieldGet(this, _remoteDb).close(); | ||
} | ||
} | ||
@@ -304,3 +309,3 @@ render() { | ||
}); | ||
const props = { | ||
const value = { | ||
db: __classPrivateFieldGet(this, _localDb), | ||
@@ -317,11 +322,14 @@ remoteDb: __classPrivateFieldGet(this, _remoteDb), | ||
}; | ||
return (React.createElement(exports.Context.Provider, { value: value }, this.renderChildren())); | ||
} | ||
renderChildren() { | ||
// We have loaded our remote database but we are not authenticated | ||
if (this.props.scaffold && !this.state.authenticated) { | ||
if (this.state.internalRoute === ROUTE_SIGNUP) { | ||
return React.cloneElement(this.props.signup, props); | ||
return React.cloneElement(this.props.signup); | ||
} | ||
// If we aren't on the signup screen we should return the login screen | ||
return React.cloneElement(this.props.login, props); | ||
return React.cloneElement(this.props.login); | ||
} | ||
return (React.createElement(exports.Context.Provider, { value: props }, this.props.children)); | ||
return this.props.children; | ||
} | ||
@@ -332,4 +340,4 @@ } | ||
Authentication.defaultProps = { | ||
login: React.createElement(__1.Login, { component: __1.LoginView }), | ||
signup: React.createElement(__1.SignUp, { component: __1.SignUpView }), | ||
login: React.createElement(Login_1.Login, { component: LoginView_1.LoginView }), | ||
signup: React.createElement(SignUp_1.SignUp, { component: SignUpView_1.SignUpView }), | ||
loading: React.createElement(React.Fragment, null, "Loading..."), | ||
@@ -336,0 +344,0 @@ debug: false, |
@@ -5,5 +5,2 @@ import * as React from "react"; | ||
component?: React.ComponentType<LoginViewProps>; | ||
error?: string; | ||
login?(username: string, password: string): void; | ||
navigateToSignUp?(): void; | ||
} | ||
@@ -10,0 +7,0 @@ export declare class Login extends React.Component<LoginProps> { |
@@ -27,6 +27,7 @@ "use strict"; | ||
}; | ||
var _setUsername, _setPassword, _login; | ||
var _setUsername, _setPassword; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Login = void 0; | ||
const React = __importStar(require("react")); | ||
const Authentication_1 = require("./Authentication"); | ||
const LoginView_1 = require("./LoginView"); | ||
@@ -42,21 +43,22 @@ class Login extends React.Component { | ||
_setPassword.set(this, (event) => this.setState({ password: event.target.value })); | ||
_login.set(this, () => { | ||
this.props.login(this.state.username, this.state.password); | ||
}); | ||
} | ||
render() { | ||
const props = { | ||
error: this.props.error, | ||
login: __classPrivateFieldGet(this, _login), | ||
navigateToSignUp: this.props.navigateToSignUp, | ||
username: this.state.username, | ||
setUsername: __classPrivateFieldGet(this, _setUsername), | ||
password: this.state.password, | ||
setPassword: __classPrivateFieldGet(this, _setPassword), | ||
}; | ||
return React.createElement(this.props.component, props); | ||
return (React.createElement(Authentication_1.Context.Consumer, null, ({ error, login, navigateToSignUp, }) => { | ||
const props = { | ||
error, | ||
login: () => { | ||
login(this.state.username, this.state.password); | ||
}, | ||
navigateToSignUp, | ||
username: this.state.username, | ||
setUsername: __classPrivateFieldGet(this, _setUsername), | ||
password: this.state.password, | ||
setPassword: __classPrivateFieldGet(this, _setPassword), | ||
}; | ||
return React.createElement(this.props.component, props); | ||
})); | ||
} | ||
} | ||
exports.Login = Login; | ||
_setUsername = new WeakMap(), _setPassword = new WeakMap(), _login = new WeakMap(); | ||
_setUsername = new WeakMap(), _setPassword = new WeakMap(); | ||
Login.defaultProps = { | ||
@@ -63,0 +65,0 @@ component: LoginView_1.LoginView, |
@@ -5,5 +5,2 @@ import * as React from "react"; | ||
component?: React.ComponentType<SignUpViewProps>; | ||
error?: string; | ||
signUp?(username: string, password: string, email: string): void; | ||
navigateToLogin?(): void; | ||
} | ||
@@ -10,0 +7,0 @@ export declare class SignUp extends React.Component<SignUpProps> { |
@@ -27,6 +27,7 @@ "use strict"; | ||
}; | ||
var _setUsername, _setEmail, _setPassword, _signUp; | ||
var _setUsername, _setEmail, _setPassword; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SignUp = void 0; | ||
const React = __importStar(require("react")); | ||
const Authentication_1 = require("./Authentication"); | ||
const SignUpView_1 = require("./SignUpView"); | ||
@@ -46,23 +47,24 @@ class SignUp extends React.Component { | ||
_setPassword.set(this, (event) => this.setState({ password: event.target.value })); | ||
_signUp.set(this, () => { | ||
this.props.signUp(this.state.username, this.state.password, this.state.email); | ||
}); | ||
} | ||
render() { | ||
const props = { | ||
error: this.props.error, | ||
signUp: __classPrivateFieldGet(this, _signUp), | ||
navigateToLogin: this.props.navigateToLogin, | ||
email: this.state.email, | ||
setEmail: __classPrivateFieldGet(this, _setEmail), | ||
username: this.state.username, | ||
setUsername: __classPrivateFieldGet(this, _setUsername), | ||
password: this.state.password, | ||
setPassword: __classPrivateFieldGet(this, _setPassword), | ||
}; | ||
return React.createElement(this.props.component, props); | ||
return (React.createElement(Authentication_1.Context.Consumer, null, ({ error, signUp, navigateToLogin, }) => { | ||
const props = { | ||
error, | ||
signUp: () => { | ||
signUp(this.state.username, this.state.password, this.state.email); | ||
}, | ||
navigateToLogin, | ||
email: this.state.email, | ||
setEmail: __classPrivateFieldGet(this, _setEmail), | ||
username: this.state.username, | ||
setUsername: __classPrivateFieldGet(this, _setUsername), | ||
password: this.state.password, | ||
setPassword: __classPrivateFieldGet(this, _setPassword), | ||
}; | ||
return React.createElement(this.props.component, props); | ||
})); | ||
} | ||
} | ||
exports.SignUp = SignUp; | ||
_setUsername = new WeakMap(), _setEmail = new WeakMap(), _setPassword = new WeakMap(), _signUp = new WeakMap(); | ||
_setUsername = new WeakMap(), _setEmail = new WeakMap(), _setPassword = new WeakMap(); | ||
SignUp.defaultProps = { | ||
@@ -69,0 +71,0 @@ component: SignUpView_1.SignUpView, |
@@ -24,7 +24,7 @@ "use strict"; | ||
const React = __importStar(require("react")); | ||
const __1 = require("../"); | ||
const Authentication_1 = require("./Authentication"); | ||
function Unauthenticated({ children, }) { | ||
return (React.createElement(__1.Context.Consumer, null, ({ authenticated }) => authenticated ? null : children)); | ||
return (React.createElement(Authentication_1.Context.Consumer, null, ({ authenticated }) => authenticated ? null : children)); | ||
} | ||
exports.Unauthenticated = Unauthenticated; | ||
//# sourceMappingURL=Unauthenticated.js.map |
{ | ||
"name": "@stanlemon/react-couchdb-authentication", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "React component for authenticating against a CouchDB user db and syncing it locally with PouchDB.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
63147
873