README
dha-login
This module is used for implementing different login capabilities.
Getting Started
Install
Install from npm:
- npm i dha-login dha-db dha-encryption platform pouchdb pouchdb-upsert
- npm i -D @types/platform @types/pouchdb @types/pouchdb-upsert
LogInWithPin Component
Routes.tsx - Functional component
import { PageNotFound } from 'components';
import { Home } from 'containers';
import { LogInWithPin } from 'dha-login';
import React from 'react';
import { HashRouter, Route, Switch } from 'react-router-dom';
const Routes: React.FC = () => (
<HashRouter>
<Switch>
<Route component={LogInWithPin} exact={true} path="/" />
<Route component={Home} path="/home" />
<Route component={PageNotFound} />
</Switch>
</HashRouter>
);
export default Routes;
Routes.tsx - Class component
import { PageNotFound } from 'components';
import { Home } from 'containers';
import { LogInWithPin } from 'dha-login';
import React from 'react';
import { HashRouter, Route, Switch } from 'react-router-dom';
class Routes extends React.Component {
render() {
return (
<HashRouter>
<Switch>
<Route component={LogInWithPin} exact={true} path="/" />
<Route component={Home} path="/home" />
<Route component={PageNotFound} />
</Switch>
</HashRouter>
);
}
}
export default Routes;
Contribute
Setup
- SSH: git clone git@bitbucket.org:wmtp/dha-login.git
- HTTPS: git clone https://username@bitbucket.org/wmtp/dha-login.git
- cd dha-login
- git checkout dev (if necessary, never work directly in master branch)
- npm i
Build
The package uses the Typescript compiler (TSC) to build the source code. To build the project run the following command:
- npm run build
Link peerDependencies
Note: You must tell the local dha-login to use all peerDependencies from the app you are including the dha-login into using npm link (the example below is for using the dha-login in the pwa-starter).
See the dha-login package.json peerDependencies section.
"peerDependencies": {
"@material-ui/core": "^X.X.X",
"@material-ui/icons": "^X.X.X",
"react": "^X.X.X",
"react-dom": "^X.X.X"
}
- npm link ../pwa-starter/node_modules/@material-ui/core
- npm link ../pwa-starter/node_modules/@material-ui/icons
- npm link ../pwa-starter/node_modules/@material-ui/styles
- This is not a listed peerDependency, but will throw a warning in the console that multiple instances of @material-ui/styles exists.
- npm link ../pwa-starter/node_modules/react
- npm link ../pwa-starter/node_modules/react-dom
- Repeat for any remaining peerDependencies that are not listed.
Install Local
You can install the package into your own React application/pwa-starter as a dependency. After you build the dha-login, install the package into the app using the following command:
- cd pwa-starter
- npm i /abs/or/rel/path/to/dha-login or npm link /abs/or/rel/path/to/dha-login
- ex. npm i ../dha-login or npm link ../dha-login
- pwa-starter and dha-login are sibling folders in the example. Adjust this to your project name and directory structure.
- ex. npm i ../dha-login or npm link ../dha-login
Troubleshooting
Npm Install Issues
- Clearing the package-lock.json and node_modules folder can help ensure that an app or package starts in a clean state.
- rm -rf package-lock.json node_modules
Hook Errors
- Hook errors can be caused when a local package is installed into an application where the package devDependencies conflict with the application dependencies by having multiple instances of the same dependency.
- You must tell the local dha-login to use peerDependencies from the app you are including the dha-login into using npm link (the example below is for using the dha-login in the pwa-starter).
- Refer to "Link peerDependencies" section above.
- npm link ../pwa-starter/node_modules/@material-ui/core
- Refer to "Link peerDependencies" section above.
Test
- Tests can be ran with the
npm testcommand. - Tests are ran using Jest with Enzyme - More information about getting started with Jest can be found here.
Example:
test('renders without crashing', () => {
shallow(<Demo prop1="1" prop2={2} />);
});
test('hello world string', () => {
expect(demo()).toMatch(`RENAME Demo files to start.`);
});
Source Code
https://bitbucket.org/wmtp/dha-login
NPM
https://www.npmjs.com/package/dha-login
License
This project is licensed under the MIT License.