@stanlemon/react-couchdb-authentication
Advanced tools
Comparing version 0.8.7 to 0.8.8
@@ -1,13 +0,10 @@ | ||
import * as React from "react"; | ||
import { Context } from "./Authentication.js"; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
export function Authenticated({ | ||
children | ||
}) { | ||
return /*#__PURE__*/_jsx(Context.Consumer, { | ||
children: ({ | ||
authenticated | ||
}) => authenticated ? children : null | ||
}); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Authenticated = void 0; | ||
const jsx_runtime_1 = require("react/jsx-runtime"); | ||
const Authentication_1 = require("./Authentication"); | ||
function Authenticated({ children, }) { | ||
return ((0, jsx_runtime_1.jsx)(Authentication_1.Context.Consumer, { children: ({ authenticated }) => (authenticated ? children : null) })); | ||
} | ||
exports.Authenticated = Authenticated; | ||
//# sourceMappingURL=Authenticated.js.map |
@@ -1,47 +0,63 @@ | ||
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } | ||
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); } | ||
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } | ||
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; } | ||
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); } | ||
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } } | ||
import * as React from "react"; | ||
import PouchDB from "pouchdb"; | ||
import retry from "async-retry"; | ||
import { Login } from "./Login.js"; | ||
import { LoginView } from "./LoginView.js"; | ||
import { SignUp } from "./SignUp.js"; | ||
import { SignUpView } from "./SignUpView.js"; | ||
import { Buffer } from "buffer"; | ||
import { setIntervalAsync, clearIntervalAsync } from "set-interval-async/dynamic"; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
import { Fragment as _Fragment } from "react/jsx-runtime"; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Authentication = exports.Context = void 0; | ||
const jsx_runtime_1 = require("react/jsx-runtime"); | ||
const React = __importStar(require("react")); | ||
const pouchdb_1 = __importDefault(require("pouchdb")); | ||
const async_retry_1 = __importDefault(require("async-retry")); | ||
const Login_1 = require("./Login"); | ||
const LoginView_1 = require("./LoginView"); | ||
const SignUp_1 = require("./SignUp"); | ||
const SignUpView_1 = require("./SignUpView"); | ||
const buffer_1 = require("buffer"); | ||
const dynamic_1 = require("set-interval-async/dynamic"); | ||
const ROUTE_LOGIN = "login"; | ||
const ROUTE_SIGNUP = "signup"; | ||
export const Context = /*#__PURE__*/React.createContext({ | ||
db: undefined, | ||
remoteDb: undefined, | ||
authenticated: false, | ||
user: undefined, | ||
error: "", | ||
login: (username, password) => {// Empty | ||
}, | ||
logout: () => {// Empty | ||
}, | ||
signUp: (username, password, email) => { | ||
return Promise.resolve(); | ||
}, | ||
navigateToLogin: () => {// Empty | ||
}, | ||
navigateToSignUp: () => {// Empty | ||
} | ||
exports.Context = React.createContext({ | ||
db: undefined, | ||
remoteDb: undefined, | ||
authenticated: false, | ||
user: undefined, | ||
error: "", | ||
login: (username, password) => { | ||
// Empty | ||
}, | ||
logout: () => { | ||
// Empty | ||
}, | ||
signUp: (username, password, email) => { | ||
return Promise.resolve(); | ||
}, | ||
navigateToLogin: () => { | ||
// Empty | ||
}, | ||
navigateToSignUp: () => { | ||
// Empty | ||
}, | ||
}); | ||
@@ -51,394 +67,313 @@ /** | ||
*/ | ||
var _localDb = /*#__PURE__*/new WeakMap(); | ||
var _remoteDb = /*#__PURE__*/new WeakMap(); | ||
var _syncHandler = /*#__PURE__*/new WeakMap(); | ||
var _checkSessionInterval = /*#__PURE__*/new WeakMap(); | ||
export class Authentication extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
_defineProperty(this, "state", { | ||
// If errors bubble up and need to be provided to the login screen | ||
error: undefined, | ||
// Used to denote before/after we've attempted an initial login | ||
loaded: false, | ||
// Whether or not a user is logged in | ||
authenticated: false, | ||
// User object, if they are logged in | ||
user: undefined, | ||
// Internal route path, defaults to the login screen | ||
internalRoute: ROUTE_LOGIN | ||
}); | ||
_classPrivateFieldInitSpec(this, _localDb, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldInitSpec(this, _remoteDb, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldInitSpec(this, _syncHandler, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldInitSpec(this, _checkSessionInterval, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_defineProperty(this, "signUp", async (username, password, email) => { | ||
if (!username || !password || !email) { | ||
this.setState({ | ||
error: "Username, password and email are required fields." | ||
}); | ||
return; | ||
} | ||
const userId = "org.couchdb.user:" + username; | ||
const user = { | ||
name: username, | ||
password, | ||
roles: [], | ||
type: "user", | ||
_id: userId, | ||
// TODO: Allow for any metadata | ||
metadata: { | ||
class Authentication extends React.Component { | ||
static defaultProps = { | ||
login: (0, jsx_runtime_1.jsx)(Login_1.Login, { component: LoginView_1.LoginView }), | ||
signup: (0, jsx_runtime_1.jsx)(SignUp_1.SignUp, { component: SignUpView_1.SignUpView }), | ||
loading: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "Loading..." }), | ||
debug: false, | ||
sync: true, | ||
localDbName: "user", | ||
adapter: "idb", | ||
sessionInterval: 15000, | ||
scaffold: true, | ||
}; | ||
state = { | ||
// If errors bubble up and need to be provided to the login screen | ||
error: undefined, | ||
// Used to denote before/after we've attempted an initial login | ||
loaded: false, | ||
// Whether or not a user is logged in | ||
authenticated: false, | ||
// User object, if they are logged in | ||
user: undefined, | ||
// Internal route path, defaults to the login screen | ||
internalRoute: ROUTE_LOGIN, | ||
}; | ||
#localDb; | ||
#remoteDb; | ||
#syncHandler; | ||
#checkSessionInterval; | ||
constructor(props) { | ||
super(props); | ||
if (!this.props.url) { | ||
throw new Error("A url to a couchdb instance is required"); | ||
} | ||
}; | ||
try { | ||
const response = await this.fetch(this.props.url + "_users/" + userId, { | ||
method: "PUT", | ||
body: JSON.stringify(user) | ||
this.#localDb = new pouchdb_1.default(this.props.localDbName, { | ||
adapter: this.props.adapter, | ||
}); | ||
if (response.error) { | ||
//{error: "conflict", reason: "Document update conflict."} | ||
this.setState({ | ||
error: response.reason | ||
}); | ||
return; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
log(...args) { | ||
if (this.props.debug) { | ||
// eslint-disable-next-line no-console | ||
console.log.apply(null, args); | ||
} | ||
if (!response.ok) { | ||
this.setState({ | ||
error: "An unknown error has occurred" | ||
}); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
error(...args) { | ||
if (this.props.debug) { | ||
// eslint-disable-next-line no-console | ||
console.error.apply(null, args); | ||
} | ||
await this.checkForDb(username); | ||
await this.login(username, password); | ||
} catch (err) { | ||
this.error(err); | ||
} | ||
}); | ||
_defineProperty(this, "logout", () => { | ||
void (async () => { | ||
} | ||
getUserDb(username) { | ||
if (!username) { | ||
return null; | ||
} | ||
const buffer = buffer_1.Buffer.from(username); | ||
const hexUsername = buffer.toString("hex"); | ||
return "userdb-" + hexUsername; | ||
} | ||
getUserDbUrl(username) { | ||
return (this.props.url.substring(0, this.props.url.lastIndexOf("/") + 1) + | ||
(this.getUserDb(username) || "")); | ||
} | ||
signUp = async (username, password, email) => { | ||
if (!username || !password || !email) { | ||
this.setState({ | ||
error: "Username, password and email are required fields.", | ||
}); | ||
return; | ||
} | ||
const userId = "org.couchdb.user:" + username; | ||
const user = { | ||
name: username, | ||
password, | ||
roles: [], | ||
type: "user", | ||
_id: userId, | ||
// TODO: Allow for any metadata | ||
metadata: { email }, | ||
}; | ||
try { | ||
await this.fetch(this.props.url + "_session", { | ||
method: "DELETE" | ||
}); // Clear the user and redirect them to our login screen | ||
this.setState({ | ||
user: undefined, | ||
authenticated: false, | ||
internalRoute: ROUTE_LOGIN | ||
}); | ||
} catch (err) { | ||
this.error(err); | ||
const response = await this.fetch(this.props.url + "_users/" + userId, { | ||
method: "PUT", | ||
body: JSON.stringify(user), | ||
}); | ||
if (response.error) { | ||
//{error: "conflict", reason: "Document update conflict."} | ||
this.setState({ error: response.reason }); | ||
return; | ||
} | ||
if (!response.ok) { | ||
this.setState({ error: "An unknown error has occurred" }); | ||
} | ||
await this.checkForDb(username); | ||
await this.login(username, password); | ||
} | ||
})(); | ||
}); | ||
_defineProperty(this, "login", async (username, password) => { | ||
if (!username || !password) { | ||
this.setState({ | ||
error: "Invalid login" | ||
}); | ||
return; | ||
} | ||
try { | ||
const response = await this.fetch(this.props.url + "_session", { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
username, | ||
password | ||
}) | ||
}); | ||
const userError = response; // If the login fails, set the reason as error and make sure we show as unauthenticated | ||
if (!userError || userError.error) { | ||
this.setState({ | ||
authenticated: false, | ||
error: userError.reason | ||
}); | ||
return; | ||
catch (err) { | ||
this.error(err); | ||
} | ||
const user = response; | ||
this.setState({ | ||
authenticated: true, | ||
user | ||
}); | ||
this.setupDb(username, password); | ||
} catch (err) { | ||
this.setState({ | ||
authenticated: false, | ||
user: undefined | ||
}); | ||
this.error(err); | ||
} | ||
}); | ||
if (!this.props.url) { | ||
throw new Error("A url to a couchdb instance is required"); | ||
}; | ||
async checkForDb(username) { | ||
await (0, async_retry_1.default)(async () => { | ||
const info = await this.fetch(this.getUserDbUrl(username)); | ||
const isFound = info.error === "not_found" || | ||
(info.error === "forbidden" && | ||
info.reason && | ||
(info.reason === "You are not allowed to access this db." || | ||
info.reason === "_reader access is required for this request")); | ||
if (!isFound) { | ||
throw Error("Cannot find database " + username); | ||
} | ||
return info; | ||
}, { retries: 5 }); | ||
} | ||
_classPrivateFieldSet(this, _localDb, new PouchDB(this.props.localDbName, { | ||
adapter: this.props.adapter | ||
})); | ||
} // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
log(...args) { | ||
if (this.props.debug) { | ||
// eslint-disable-next-line no-console | ||
console.log.apply(null, args); | ||
fetch(url, options = {}) { | ||
return fetch(url, { | ||
...options, | ||
...{ | ||
cache: "no-cache", | ||
credentials: "include", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
}).then((r) => r.json()); | ||
} | ||
} // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
error(...args) { | ||
if (this.props.debug) { | ||
// eslint-disable-next-line no-console | ||
console.error.apply(null, args); | ||
async grabSession() { | ||
// If we have a remoteDb, we'll use it. This works better in Safari which does | ||
// not support storing cross-origin cookies across multiple requests. | ||
if (this.#remoteDb && | ||
this.state && | ||
this.state.user && | ||
this.state.user.name) { | ||
const user = await this.fetch(`${this.props.url}/_users/org.couchdb.user:${this.state.user.name}`).catch((err) => this.error(err)); | ||
return user; | ||
} | ||
else { | ||
const session = await this.fetch(this.props.url + "_session"); | ||
return session.userCtx; | ||
} | ||
} | ||
} | ||
getUserDb(username) { | ||
if (!username) { | ||
return null; | ||
async checkSession() { | ||
try { | ||
const user = await this.grabSession(); | ||
this.log("User session", user); | ||
const isLoggedIn = user !== null && user.name !== null; | ||
this.setState({ | ||
loaded: true, | ||
authenticated: isLoggedIn, | ||
user, | ||
}); | ||
// If we are logged in and have not yet setup our remote db connection, set it up | ||
if (isLoggedIn && !this.#remoteDb) { | ||
this.log("User is already logged in, setting up db."); | ||
this.setupDb(); | ||
// Immediately check the session again so we fully load the user | ||
await this.checkSession(); | ||
} | ||
} | ||
catch (err) { | ||
this.error(err); | ||
this.setState({ loaded: true, user: undefined, authenticated: false }); | ||
} | ||
} | ||
const buffer = Buffer.from(username); | ||
const hexUsername = buffer.toString("hex"); | ||
return "userdb-" + hexUsername; | ||
} | ||
getUserDbUrl(username) { | ||
return this.props.url.substring(0, this.props.url.lastIndexOf("/") + 1) + (this.getUserDb(username) || ""); | ||
} | ||
async checkForDb(username) { | ||
await retry(async () => { | ||
const info = await this.fetch(this.getUserDbUrl(username)); | ||
const isFound = info.error === "not_found" || info.error === "forbidden" && info.reason && (info.reason === "You are not allowed to access this db." || info.reason === "_reader access is required for this request"); | ||
if (!isFound) { | ||
throw Error("Cannot find database " + username); | ||
} | ||
return info; | ||
}, { | ||
retries: 5 | ||
}); | ||
} | ||
fetch(url, options = {}) { | ||
return fetch(url, { ...options, | ||
...{ | ||
cache: "no-cache", | ||
credentials: "include", | ||
headers: { | ||
"Content-Type": "application/json" | ||
logout = () => { | ||
void (async () => { | ||
try { | ||
await this.fetch(this.props.url + "_session", { | ||
method: "DELETE", | ||
}); | ||
// Clear the user and redirect them to our login screen | ||
this.setState({ | ||
user: undefined, | ||
authenticated: false, | ||
internalRoute: ROUTE_LOGIN, | ||
}); | ||
} | ||
catch (err) { | ||
this.error(err); | ||
} | ||
})(); | ||
}; | ||
login = async (username, password) => { | ||
if (!username || !password) { | ||
this.setState({ error: "Invalid login" }); | ||
return; | ||
} | ||
} | ||
}).then(r => r.json()); | ||
} | ||
async grabSession() { | ||
// If we have a remoteDb, we'll use it. This works better in Safari which does | ||
// not support storing cross-origin cookies across multiple requests. | ||
if (_classPrivateFieldGet(this, _remoteDb) && this.state && this.state.user && this.state.user.name) { | ||
const user = await this.fetch(`${this.props.url}/_users/org.couchdb.user:${this.state.user.name}`).catch(err => this.error(err)); | ||
return user; | ||
} else { | ||
const session = await this.fetch(this.props.url + "_session"); | ||
return session.userCtx; | ||
try { | ||
const response = await this.fetch(this.props.url + "_session", { | ||
method: "POST", | ||
body: JSON.stringify({ username, password }), | ||
}); | ||
const userError = response; | ||
// If the login fails, set the reason as error and make sure we show as unauthenticated | ||
if (!userError || userError.error) { | ||
this.setState({ | ||
authenticated: false, | ||
error: userError.reason, | ||
}); | ||
return; | ||
} | ||
const user = response; | ||
this.setState({ authenticated: true, user }); | ||
this.setupDb(username, password); | ||
} | ||
catch (err) { | ||
this.setState({ authenticated: false, user: undefined }); | ||
this.error(err); | ||
} | ||
}; | ||
setupDb(username, password) { | ||
const opts = { | ||
skip_setup: true, | ||
fetch: (url, opts) => { | ||
// In PouchDB 7.0 they dropped this and it breaks cookie authentication, so we set this explicitly | ||
opts.credentials = "include"; | ||
return pouchdb_1.default.fetch(url, opts); | ||
}, | ||
// Safari does some weird stuff if we don't do this, Chrome and Firefox work fine | ||
...(username && password | ||
? { | ||
auth: { | ||
username, | ||
password, | ||
}, | ||
} | ||
: {}), | ||
}; | ||
if (!this.state.user || !this.state.user.name) { | ||
return; | ||
} | ||
const userDbUrl = this.getUserDbUrl(this.state.user.name); | ||
this.#remoteDb = new pouchdb_1.default(userDbUrl, opts); | ||
// This is because we're setting important properties that aren't in state | ||
this.forceUpdate(); | ||
if (!this.props.sync) { | ||
this.log("Sync is disabled"); | ||
return; | ||
} | ||
this.#syncHandler = pouchdb_1.default.sync(this.#localDb, this.#remoteDb, { | ||
live: true, | ||
retry: true, | ||
}); | ||
this.#syncHandler | ||
.on("change", (info) => this.log("Change", info)) | ||
.on("paused", (info) => this.log("Syncing Paused", info)) | ||
.on("complete", (info) => this.log("Complete", info)) | ||
.on("error", (err) => this.error("Error", err)) | ||
.catch((err) => this.error(err)); | ||
} | ||
} | ||
async checkSession() { | ||
try { | ||
const user = await this.grabSession(); | ||
this.log("User session", user); | ||
const isLoggedIn = user !== null && user.name !== null; | ||
this.setState({ | ||
loaded: true, | ||
authenticated: isLoggedIn, | ||
user | ||
}); // If we are logged in and have not yet setup our remote db connection, set it up | ||
if (isLoggedIn && !_classPrivateFieldGet(this, _remoteDb)) { | ||
this.log("User is already logged in, setting up db."); | ||
this.setupDb(); // Immediately check the session again so we fully load the user | ||
async componentDidMount() { | ||
await this.checkSession(); | ||
} | ||
} catch (err) { | ||
this.error(err); | ||
this.setState({ | ||
loaded: true, | ||
user: undefined, | ||
authenticated: false | ||
}); | ||
this.#checkSessionInterval = (0, dynamic_1.setIntervalAsync)(async () => { | ||
await this.checkSession(); | ||
}, this.props.sessionInterval); | ||
} | ||
} | ||
setupDb(username, password) { | ||
const opts = { | ||
skip_setup: true, | ||
fetch: (url, opts) => { | ||
// In PouchDB 7.0 they dropped this and it breaks cookie authentication, so we set this explicitly | ||
opts.credentials = "include"; | ||
return PouchDB.fetch(url, opts); | ||
}, | ||
// Safari does some weird stuff if we don't do this, Chrome and Firefox work fine | ||
...(username && password ? { | ||
auth: { | ||
username, | ||
password | ||
async componentWillUnmount() { | ||
if (this.#checkSessionInterval) { | ||
await (0, dynamic_1.clearIntervalAsync)(this.#checkSessionInterval); | ||
} | ||
} : {}) | ||
}; | ||
if (!this.state.user || !this.state.user.name) { | ||
return; | ||
// Will not be set if sync has been disabled | ||
if (this.#syncHandler) { | ||
this.#syncHandler.cancel(); | ||
} | ||
if (this.#remoteDb) { | ||
await this.#remoteDb.close(); | ||
} | ||
} | ||
const userDbUrl = this.getUserDbUrl(this.state.user.name); | ||
_classPrivateFieldSet(this, _remoteDb, new PouchDB(userDbUrl, opts)); // This is because we're setting important properties that aren't in state | ||
this.forceUpdate(); | ||
if (!this.props.sync) { | ||
this.log("Sync is disabled"); | ||
return; | ||
render() { | ||
// If we haven't completed our initial load yet, show a loader | ||
if (!this.state.loaded || !this.#localDb) { | ||
this.log("Waiting for initial database"); | ||
return this.props.loading; | ||
} | ||
// Switches to the login screen and clears out any errors | ||
const navigateToLogin = () => this.setState({ | ||
error: undefined, | ||
internalRoute: ROUTE_LOGIN, | ||
}); | ||
// Switches to the sign up screen and clears out any errors | ||
const navigateToSignUp = () => this.setState({ | ||
error: undefined, | ||
internalRoute: ROUTE_SIGNUP, | ||
}); | ||
const value = { | ||
db: this.#localDb, | ||
remoteDb: this.#remoteDb, | ||
authenticated: this.state.authenticated, | ||
user: this.state.user, | ||
error: this.state.error, | ||
login: this.login, | ||
logout: this.logout, | ||
signUp: this.signUp, | ||
navigateToLogin, | ||
navigateToSignUp, | ||
}; | ||
return ((0, jsx_runtime_1.jsx)(exports.Context.Provider, { value: value, children: this.renderChildren() })); | ||
} | ||
_classPrivateFieldSet(this, _syncHandler, PouchDB.sync(_classPrivateFieldGet(this, _localDb), _classPrivateFieldGet(this, _remoteDb), { | ||
live: true, | ||
retry: true | ||
})); | ||
_classPrivateFieldGet(this, _syncHandler).on("change", info => this.log("Change", info)).on("paused", info => this.log("Syncing Paused", info)).on("complete", info => this.log("Complete", info)).on("error", err => this.error("Error", err)).catch(err => this.error(err)); | ||
} | ||
async componentDidMount() { | ||
await this.checkSession(); | ||
_classPrivateFieldSet(this, _checkSessionInterval, setIntervalAsync(async () => { | ||
await this.checkSession(); | ||
}, this.props.sessionInterval)); | ||
} | ||
async componentWillUnmount() { | ||
if (_classPrivateFieldGet(this, _checkSessionInterval)) { | ||
await clearIntervalAsync(_classPrivateFieldGet(this, _checkSessionInterval)); | ||
} // Will not be set if sync has been disabled | ||
if (_classPrivateFieldGet(this, _syncHandler)) { | ||
_classPrivateFieldGet(this, _syncHandler).cancel(); | ||
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); | ||
} | ||
// If we aren't on the signup screen we should return the login screen | ||
return React.cloneElement(this.props.login); | ||
} | ||
return this.props.children; | ||
} | ||
if (_classPrivateFieldGet(this, _remoteDb)) { | ||
await _classPrivateFieldGet(this, _remoteDb).close(); | ||
} | ||
} | ||
render() { | ||
// If we haven't completed our initial load yet, show a loader | ||
if (!this.state.loaded || !_classPrivateFieldGet(this, _localDb)) { | ||
this.log("Waiting for initial database"); | ||
return this.props.loading; | ||
} // Switches to the login screen and clears out any errors | ||
const navigateToLogin = () => this.setState({ | ||
error: undefined, | ||
internalRoute: ROUTE_LOGIN | ||
}); // Switches to the sign up screen and clears out any errors | ||
const navigateToSignUp = () => this.setState({ | ||
error: undefined, | ||
internalRoute: ROUTE_SIGNUP | ||
}); | ||
const value = { | ||
db: _classPrivateFieldGet(this, _localDb), | ||
remoteDb: _classPrivateFieldGet(this, _remoteDb), | ||
authenticated: this.state.authenticated, | ||
user: this.state.user, | ||
error: this.state.error, | ||
login: this.login, | ||
logout: this.logout, | ||
signUp: this.signUp, | ||
navigateToLogin, | ||
navigateToSignUp | ||
}; | ||
return /*#__PURE__*/_jsx(Context.Provider, { | ||
value: value, | ||
children: 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 /*#__PURE__*/React.cloneElement(this.props.signup); | ||
} // If we aren't on the signup screen we should return the login screen | ||
return /*#__PURE__*/React.cloneElement(this.props.login); | ||
} | ||
return this.props.children; | ||
} | ||
} | ||
_defineProperty(Authentication, "defaultProps", { | ||
login: /*#__PURE__*/_jsx(Login, { | ||
component: LoginView | ||
}), | ||
signup: /*#__PURE__*/_jsx(SignUp, { | ||
component: SignUpView | ||
}), | ||
loading: /*#__PURE__*/_jsx(_Fragment, { | ||
children: "Loading..." | ||
}), | ||
debug: false, | ||
sync: true, | ||
localDbName: "user", | ||
adapter: "idb", | ||
sessionInterval: 15000, | ||
scaffold: true | ||
}); | ||
exports.Authentication = Authentication; | ||
//# sourceMappingURL=Authentication.js.map |
@@ -1,72 +0,57 @@ | ||
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } | ||
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); } | ||
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); } | ||
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } | ||
import * as React from "react"; | ||
import { Context } from "./Authentication.js"; | ||
import { LoginView } from "./LoginView.js"; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
var _setUsername = /*#__PURE__*/new WeakMap(); | ||
var _setPassword = /*#__PURE__*/new WeakMap(); | ||
export class Login extends React.Component { | ||
constructor(...args) { | ||
super(...args); | ||
_defineProperty(this, "state", { | ||
username: "", | ||
password: "" | ||
}); | ||
_classPrivateFieldInitSpec(this, _setUsername, { | ||
writable: true, | ||
value: event => this.setState({ | ||
username: event.target.value | ||
}) | ||
}); | ||
_classPrivateFieldInitSpec(this, _setPassword, { | ||
writable: true, | ||
value: event => this.setState({ | ||
password: event.target.value | ||
}) | ||
}); | ||
} | ||
render() { | ||
return /*#__PURE__*/_jsx(Context.Consumer, { | ||
children: ({ | ||
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 /*#__PURE__*/React.createElement(this.props.component, props); | ||
} | ||
}); | ||
} | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Login = void 0; | ||
const jsx_runtime_1 = require("react/jsx-runtime"); | ||
const React = __importStar(require("react")); | ||
const Authentication_1 = require("./Authentication"); | ||
const LoginView_1 = require("./LoginView"); | ||
class Login extends React.Component { | ||
static defaultProps = { | ||
component: LoginView_1.LoginView, | ||
}; | ||
state = { | ||
username: "", | ||
password: "", | ||
}; | ||
#setUsername = (event) => this.setState({ username: event.target.value }); | ||
#setPassword = (event) => this.setState({ password: event.target.value }); | ||
render() { | ||
return ((0, jsx_runtime_1.jsx)(Authentication_1.Context.Consumer, { children: ({ error, login, navigateToSignUp }) => { | ||
const props = { | ||
error, | ||
login: () => login(this.state.username, this.state.password), | ||
navigateToSignUp, | ||
username: this.state.username, | ||
setUsername: this.#setUsername, | ||
password: this.state.password, | ||
setPassword: this.#setPassword, | ||
}; | ||
return React.createElement(this.props.component, props); | ||
} })); | ||
} | ||
} | ||
_defineProperty(Login, "defaultProps", { | ||
component: LoginView | ||
}); | ||
exports.Login = Login; | ||
//# sourceMappingURL=Login.js.map |
@@ -1,56 +0,19 @@ | ||
import * as React from "react"; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
import { jsxs as _jsxs } from "react/jsx-runtime"; | ||
export function LoginView(props) { | ||
const clickToSignUp = e => { | ||
e.preventDefault(); | ||
props.navigateToSignUp(); | ||
}; | ||
const hitEnter = e => { | ||
// Submit the form if they hit enter | ||
if (e.key.toLowerCase() === "enter") { | ||
props.login(); | ||
} | ||
}; | ||
return /*#__PURE__*/_jsxs("div", { | ||
children: [props.error && /*#__PURE__*/_jsx("p", { | ||
className: "error", | ||
children: props.error | ||
}), /*#__PURE__*/_jsxs("p", { | ||
children: [/*#__PURE__*/_jsx("label", { | ||
htmlFor: "username", | ||
children: "Username" | ||
}), /*#__PURE__*/_jsx("input", { | ||
id: "username", | ||
type: "text", | ||
value: props.username, | ||
onChange: props.setUsername, | ||
onKeyPress: hitEnter | ||
})] | ||
}), /*#__PURE__*/_jsxs("p", { | ||
children: [/*#__PURE__*/_jsx("label", { | ||
htmlFor: "password", | ||
children: "Password" | ||
}), /*#__PURE__*/_jsx("input", { | ||
id: "password", | ||
type: "password", | ||
value: props.password, | ||
onChange: props.setPassword, | ||
onKeyPress: hitEnter | ||
})] | ||
}), /*#__PURE__*/_jsx("button", { | ||
id: "login-button", | ||
onClick: props.login, | ||
children: "Login" | ||
}), /*#__PURE__*/_jsx("p", { | ||
children: /*#__PURE__*/_jsx("button", { | ||
"data-testid": "navigate-to-sign-up", | ||
onClick: clickToSignUp, | ||
children: "Or sign up for a new account." | ||
}) | ||
})] | ||
}); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LoginView = void 0; | ||
const jsx_runtime_1 = require("react/jsx-runtime"); | ||
function LoginView(props) { | ||
const clickToSignUp = (e) => { | ||
e.preventDefault(); | ||
props.navigateToSignUp(); | ||
}; | ||
const hitEnter = (e) => { | ||
// Submit the form if they hit enter | ||
if (e.key.toLowerCase() === "enter") { | ||
props.login(); | ||
} | ||
}; | ||
return ((0, jsx_runtime_1.jsxs)("div", { children: [props.error && (0, jsx_runtime_1.jsx)("p", { className: "error", children: props.error }), (0, jsx_runtime_1.jsxs)("p", { children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: "username", children: "Username" }), (0, jsx_runtime_1.jsx)("input", { id: "username", type: "text", value: props.username, onChange: props.setUsername, onKeyPress: hitEnter })] }), (0, jsx_runtime_1.jsxs)("p", { children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: "password", children: "Password" }), (0, jsx_runtime_1.jsx)("input", { id: "password", type: "password", value: props.password, onChange: props.setPassword, onKeyPress: hitEnter })] }), (0, jsx_runtime_1.jsx)("button", { id: "login-button", onClick: props.login, children: "Login" }), (0, jsx_runtime_1.jsx)("p", { children: (0, jsx_runtime_1.jsx)("button", { "data-testid": "navigate-to-sign-up", onClick: clickToSignUp, children: "Or sign up for a new account." }) })] })); | ||
} | ||
exports.LoginView = LoginView; | ||
//# sourceMappingURL=LoginView.js.map |
@@ -1,88 +0,65 @@ | ||
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } | ||
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); } | ||
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); } | ||
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } | ||
import * as React from "react"; | ||
import { Context } from "./Authentication.js"; | ||
import { SignUpView } from "./SignUpView.js"; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
var _setUsername = /*#__PURE__*/new WeakMap(); | ||
var _setEmail = /*#__PURE__*/new WeakMap(); | ||
var _setPassword = /*#__PURE__*/new WeakMap(); | ||
export class SignUp extends React.Component { | ||
constructor(...args) { | ||
super(...args); | ||
_defineProperty(this, "state", { | ||
username: "", | ||
email: "", | ||
password: "" | ||
}); | ||
_classPrivateFieldInitSpec(this, _setUsername, { | ||
writable: true, | ||
value: event => { | ||
this.setState({ | ||
username: event.target.value | ||
}); | ||
} | ||
}); | ||
_classPrivateFieldInitSpec(this, _setEmail, { | ||
writable: true, | ||
value: event => this.setState({ | ||
email: event.target.value | ||
}) | ||
}); | ||
_classPrivateFieldInitSpec(this, _setPassword, { | ||
writable: true, | ||
value: event => this.setState({ | ||
password: event.target.value | ||
}) | ||
}); | ||
} | ||
render() { | ||
return /*#__PURE__*/_jsx(Context.Consumer, { | ||
children: ({ | ||
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 /*#__PURE__*/React.createElement(this.props.component, props); | ||
} | ||
}); | ||
} | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SignUp = void 0; | ||
const jsx_runtime_1 = require("react/jsx-runtime"); | ||
const React = __importStar(require("react")); | ||
const Authentication_1 = require("./Authentication"); | ||
const SignUpView_1 = require("./SignUpView"); | ||
class SignUp extends React.Component { | ||
static defaultProps = { | ||
component: SignUpView_1.SignUpView, | ||
}; | ||
state = { | ||
username: "", | ||
email: "", | ||
password: "", | ||
}; | ||
#setUsername = (event) => { | ||
this.setState({ username: event.target.value }); | ||
}; | ||
#setEmail = (event) => this.setState({ email: event.target.value }); | ||
#setPassword = (event) => this.setState({ password: event.target.value }); | ||
render() { | ||
return ((0, jsx_runtime_1.jsx)(Authentication_1.Context.Consumer, { children: ({ error, signUp, navigateToLogin, }) => { | ||
const props = { | ||
error, | ||
signUp: () => { | ||
signUp(this.state.username, this.state.password, this.state.email); | ||
}, | ||
navigateToLogin, | ||
email: this.state.email, | ||
setEmail: this.#setEmail, | ||
username: this.state.username, | ||
setUsername: this.#setUsername, | ||
password: this.state.password, | ||
setPassword: this.#setPassword, | ||
}; | ||
return React.createElement(this.props.component, props); | ||
} })); | ||
} | ||
} | ||
_defineProperty(SignUp, "defaultProps", { | ||
component: SignUpView | ||
}); | ||
exports.SignUp = SignUp; | ||
//# sourceMappingURL=SignUp.js.map |
@@ -1,57 +0,13 @@ | ||
import * as React from "react"; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
import { jsxs as _jsxs } from "react/jsx-runtime"; | ||
export function SignUpView(props) { | ||
const clickToLogin = e => { | ||
e.preventDefault(); | ||
props.navigateToLogin(); | ||
}; | ||
return /*#__PURE__*/_jsxs("div", { | ||
children: [props.error && /*#__PURE__*/_jsx("div", { | ||
className: "error", | ||
children: props.error | ||
}), /*#__PURE__*/_jsxs("p", { | ||
children: [/*#__PURE__*/_jsx("label", { | ||
htmlFor: "username", | ||
children: "Username" | ||
}), /*#__PURE__*/_jsx("input", { | ||
id: "username", | ||
type: "text", | ||
value: props.username, | ||
onChange: props.setUsername | ||
})] | ||
}), /*#__PURE__*/_jsxs("p", { | ||
children: [/*#__PURE__*/_jsx("label", { | ||
htmlFor: "email", | ||
children: "Email" | ||
}), /*#__PURE__*/_jsx("input", { | ||
id: "email", | ||
type: "text", | ||
value: props.email, | ||
onChange: props.setEmail | ||
})] | ||
}), /*#__PURE__*/_jsxs("p", { | ||
children: [/*#__PURE__*/_jsx("label", { | ||
htmlFor: "password", | ||
children: "Password" | ||
}), /*#__PURE__*/_jsx("input", { | ||
id: "password", | ||
type: "password", | ||
value: props.password, | ||
onChange: props.setPassword | ||
})] | ||
}), /*#__PURE__*/_jsx("button", { | ||
id: "sign-up-button", | ||
onClick: props.signUp, | ||
children: "Sign Up" | ||
}), /*#__PURE__*/_jsx("p", { | ||
children: /*#__PURE__*/_jsx("button", { | ||
id: "navigate-to-login", | ||
onClick: clickToLogin, | ||
children: "Return to login." | ||
}) | ||
})] | ||
}); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SignUpView = void 0; | ||
const jsx_runtime_1 = require("react/jsx-runtime"); | ||
function SignUpView(props) { | ||
const clickToLogin = (e) => { | ||
e.preventDefault(); | ||
props.navigateToLogin(); | ||
}; | ||
return ((0, jsx_runtime_1.jsxs)("div", { children: [props.error && (0, jsx_runtime_1.jsx)("div", { className: "error", children: props.error }), (0, jsx_runtime_1.jsxs)("p", { children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: "username", children: "Username" }), (0, jsx_runtime_1.jsx)("input", { id: "username", type: "text", value: props.username, onChange: props.setUsername })] }), (0, jsx_runtime_1.jsxs)("p", { children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: "email", children: "Email" }), (0, jsx_runtime_1.jsx)("input", { id: "email", type: "text", value: props.email, onChange: props.setEmail })] }), (0, jsx_runtime_1.jsxs)("p", { children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: "password", children: "Password" }), (0, jsx_runtime_1.jsx)("input", { id: "password", type: "password", value: props.password, onChange: props.setPassword })] }), (0, jsx_runtime_1.jsx)("button", { id: "sign-up-button", onClick: props.signUp, children: "Sign Up" }), (0, jsx_runtime_1.jsx)("p", { children: (0, jsx_runtime_1.jsx)("button", { id: "navigate-to-login", onClick: clickToLogin, children: "Return to login." }) })] })); | ||
} | ||
exports.SignUpView = SignUpView; | ||
//# sourceMappingURL=SignUpView.js.map |
@@ -1,13 +0,10 @@ | ||
import * as React from "react"; | ||
import { Context } from "./Authentication.js"; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
export function Unauthenticated({ | ||
children | ||
}) { | ||
return /*#__PURE__*/_jsx(Context.Consumer, { | ||
children: ({ | ||
authenticated | ||
}) => authenticated ? null : children | ||
}); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Unauthenticated = void 0; | ||
const jsx_runtime_1 = require("react/jsx-runtime"); | ||
const Authentication_1 = require("./Authentication"); | ||
function Unauthenticated({ children, }) { | ||
return ((0, jsx_runtime_1.jsx)(Authentication_1.Context.Consumer, { children: ({ authenticated }) => authenticated ? null : children })); | ||
} | ||
exports.Unauthenticated = Unauthenticated; | ||
//# sourceMappingURL=Unauthenticated.js.map |
@@ -0,12 +1,28 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Supporting components | ||
export * from "./components/Authenticated.js"; | ||
export * from "./components/Login.js"; | ||
export * from "./components/LoginView.js"; | ||
export * from "./components/SignUp.js"; | ||
export * from "./components/SignUpView.js"; | ||
export * from "./components/Unauthenticated.js"; // Main component for use in applications | ||
export * from "./components/Authentication.js"; // Utilities for composing apps | ||
export * from "./utils/withAuthentication.js"; | ||
__exportStar(require("./components/Authenticated"), exports); | ||
__exportStar(require("./components/Login"), exports); | ||
__exportStar(require("./components/LoginView"), exports); | ||
__exportStar(require("./components/SignUp"), exports); | ||
__exportStar(require("./components/SignUpView"), exports); | ||
__exportStar(require("./components/Unauthenticated"), exports); | ||
// Main component for use in applications | ||
__exportStar(require("./components/Authentication"), exports); | ||
// Utilities for composing apps | ||
__exportStar(require("./utils/withAuthentication"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,20 +0,35 @@ | ||
import * as React from "react"; | ||
import { Context } from "../index.js"; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withAuthentication = void 0; | ||
const jsx_runtime_1 = require("react/jsx-runtime"); | ||
const React = __importStar(require("react")); | ||
const __1 = require("../"); | ||
//): React.FunctionComponent<Omit<P, "putDocument"> & PassThruDocumentProps> { | ||
export function withAuthentication(component) { | ||
return () => /*#__PURE__*/_jsx(Context.Consumer, { | ||
children: ({ | ||
db, | ||
remoteDb, | ||
logout, | ||
user | ||
}) => /*#__PURE__*/React.createElement(component, { | ||
db, | ||
remoteDb, | ||
logout, | ||
user | ||
}) | ||
}); | ||
function withAuthentication(component) { | ||
return () => ((0, jsx_runtime_1.jsx)(__1.Context.Consumer, { children: ({ db, remoteDb, logout, user }) => React.createElement(component, { db, remoteDb, logout, user }) })); | ||
} | ||
exports.withAuthentication = withAuthentication; | ||
//# sourceMappingURL=withAuthentication.js.map |
{ | ||
"name": "@stanlemon/react-couchdb-authentication", | ||
"version": "0.8.7", | ||
"version": "0.8.8", | ||
"description": "React component for authenticating against a CouchDB user db and syncing it locally with PouchDB.", | ||
@@ -26,3 +26,3 @@ "keywords": [ | ||
"lint:format": "eslint --fix --ext js,jsx,ts,tsx ./src/ ./example/", | ||
"build": "rm -rf ./dist/*; tsc; babel ./src --out-dir ./dist --extensions \".ts,.tsx\" --source-maps", | ||
"build": "tsc", | ||
"example": "WEBDEV_ENTRY=./example/Example.tsx webpack serve" | ||
@@ -29,0 +29,0 @@ }, |
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
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
0
2
59131
38
832