I am struggling to integrate this Custom Login auth0 service because I am facing issues with the imports. The problem arises specifically with the usage of declare var auth0: any
. Every time I attempt to use it, I encounter the following error:
EXCEPTION: Uncaught (in promise): ReferenceError: auth0 is not defined
Interestingly, when I tried implementing the same thing with the Login example by using declare var Auth0Lock: any
, it worked perfectly fine. My project is based on a .NET Core+Angular2 solution that compiles with webpack. I am unsure if there's something missing in my webpack.config.js
, so here is the configuration:
// Configuration common to both client-side and server-side bundles
var sharedConfig = {
resolve: { extensions: [ '', '.js', '.ts', '.scss' ] },
output: {
filename: '[name].js',
publicPath: '/dist/' // Webpack dev middleware, handles requests for this URL prefix
},
module: {
loaders: [
{ test: /\.ts$/, include: /ClientApp/, loader: 'ts', query: { silent: true } },
{ test: /\.ts$/, include: /ClientApp/, loader: 'angular2-router-loader' },
{ test: /\.html$/, loader: 'raw' },
{ test: /\.css$/, loader: 'to-string!css' },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url', query: { limit: 25000 } },
{ test: /\.scss$/, exclude: /node_modules/, loaders: ["raw-loader", "sass-loader"] },
{ test: /jquery\.flot\.resize\.js$/, loader: "imports?this=>window" }
]
}
};
// Configuration for client-side bundle suitable for browsers
var clientBundleConfig = merge(sharedConfig, {
entry: {
'main-client': './ClientApp/boot-client.ts'
},
output: { path: path.join(__dirname, './wwwroot/dist') },
devtool: isDevBuild ? 'inline-source-map' : null,
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [] : [
// Plugins applicable in production builds only
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin()
])
});
// Configuration for server-side (prerendering) bundle suitable for Node
var serverBundleConfig = merge(sharedConfig, {
entry: { 'main-server': './ClientApp/boot-server.ts' },
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, './ClientApp/dist')
},
target: 'node',
devtool: 'inline-source-map',
externals: [nodeExternals({ whitelist: [allFilenamesExceptJavaScript] })] //
Don't bundle .js files from node_modules
});
module.exports = [clientBundleConfig, serverBundleConfig];
While attempting to add an authBundle
as shown above, I still couldn't resolve the issue.
This is the core of my service:
// app/core/authentication/auth.service.ts
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { tokenNotExpired } from 'angular2-jwt';
import { myConfig } from './auth.config';
const auth0 = require('auth0-js').default;
@Injectable()
export class AuthService {
// Configure Auth0
private auth0 = new auth0.WebAuth({
domain: myConfig.domain,
clientID: myConfig.clientID,
redirectUri: myConfig.callbackURL,
responseType: 'token id_token'
});
constructor(private router: Router) {
}
...
Your assistance would be greatly appreciated.