-
-
Notifications
You must be signed in to change notification settings - Fork 134
Gerald Yeo edited this page Aug 15, 2018
·
6 revisions
Table of Contents
For users who are integrating with a project generated by @angular/cli
, you may face a few issues.
For example: Module ... has no default export
or Expecting options.crypto to have a randomBytes function
.
Possible causes:
- node
crypto
imports seems to be dropped after compilation by angular. - typescript transforms default
module.exports
into named exports.
In order to solve it, you can use the provided browser-compiled file instead. i.e.
// instead of doing:
import otplib from 'otplib';
otplib.authenticator.generateSecret();
// try this instead:
import { authenticator } from 'otplib/otplib-browser';
authenticator.generateSecret();
EDIT v10.0.0
introduces TypeScript definitions.
The authenticator.generateSecret()
method is provided as a convenience function. Users are free to
use their own methods to generate secret. However, the generate key must be encoded for it to be
decoded properly by authenticator.
import otplib from 'otplib';
const yourDataBackedSecret = createMyOwnSecretFunction();
const secret = otplib.Authenticator.utils.encodeKey(yourDataBackedSecret);