Challenges of Integrating Auth0 with Angular2/.NETCore Project

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.

Answer №1

After successfully getting the import feature to function, I achieved this by downloading and incorporating the most recent auth0-js typings through npm. Subsequently, I utilized

import * as auth0 from 'auth0-js';
within my auth.service.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

step-by-step guide to leveraging the heatmap functionality of google maps with angular agm

For my current Angular 5 project, I am utilizing the angular component @agm/core found at https://github.com/SebastianM/angular-google-maps to display Google Maps. It's been working well so far, but now I'm looking to incorporate a heatmap layer ...

In order to utilize Node.js/Express/Typescript, it is necessary to use the

My current project involves creating a webservice using Express, with the goal of making it executable from both localhost and an AWS Lambda function via Claudia. In order to achieve this, I am aiming to separate the app configuration from the app.listen ...

What is the best way to enhance a react-bootstrap component with TypeScript?

Currently, I am utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f1d0a0e0c1b420d00001b1c1b1d0e1f2f5e415f415f420d0a1b0e415e5b">[email protected]</a> and delving into the development of a customized Button ...

Configuring ag-grid in an Angular project

I'm facing an issue with setting up ag-grid in my existing Angular project. Our project currently has version 8.2.0 of ag-grid installed, without any additional dependencies like ag-grid-angular. Do I need to install extra dependencies for ag-grid sup ...

Steps to modify the background color of an IconButton upon clicking in Material UI

After clicking on the IconButton, the background color changes to an oval shape. I now need to modify the background color when it is clicked. CSS The CSS code for the IconButton changes the background color upon hover. I require a similar effect for the ...

An Array of objects is considered NULL if it does not contain any values before being iterated through

Working with Files in TypeScript (Angular 8) has led me to Encode the files in Base64 using the code below: private async convertToBase64(evidences: Array<EvidenceToDisplay>): Promise<Array<EvidenceToDownload>> { const results: Arr ...

The process of extracting all arrays from a JSON object

Within my JSON object, there is a list of countries each with multiple regions stored in an array. My goal is to extract and combine all the regions into one single list. However, when I attempt to map the data, it does not consolidate all the regions as e ...

Status:0 was received as the response from URL:null during the REST call made from my iOS Ionic application

I am currently facing an issue with a rest call in my Ionic app. The call works fine on Android devices but encounters problems on iOS devices. Below is the implementation of the rest call in my Ionic service. import { Http } from '@angular/http&apos ...

Explicit declaration of default parameters

Check out the helpful solution In regard to the following code snippet, type C = { a: string, b: number } function f({ a, b } = {a:"", b:0}): void { // ... } Can you explain the syntax for explicitly typing the default parameter? ...

Tips for displaying a loading spinner each time the material table is loading

Hey there, I'm currently working on an Angular project where I need to display a table using Material Table. To indicate that the table is loading, I've defined a variable called isLoading. Here's how it works: In my TypeScript file: @Com ...

Utilizing the split function within an ngIf statement in Angular

<div *ngIf="store[obj?.FundCode + obj?.PayWith].status == 'fail'">test</div> The method above is being utilized to combine two strings in order to map an array. It functions correctly, however, when attempting to incorporate the spli ...

Prevent toggle button from activating panel expansion

Is there a way to add toggle buttons to the description section of an expansion panel without triggering the expansion panel when interacting with the buttons? I have included an example here. ...

The mdb navigation bar seems to constantly change its height

Having an issue with the height of my mdb navbar in my Angular app. It randomly flips to a larger size when reloading the page, but returns to normal when I open the developer console in Chrome. Two screenshots show the correct display and the incorrect i ...

Encountering a glitch while integrating the angular-select2 module into an Ionic 3 application

Attempting to integrate the angular-select2 npm module into my ionic 3 app. Successfully installed the module using npm within my project Imported the package into my app.module.ts file Added <select2> tags into the html file of my application Enc ...

Using Inheritance to Create Custom Event/Callback Handlers in TypeScript

Currently facing an issue with Typescript that I'm stuck on. I have created a named callback Handler class that receives the allowed list of "events"/"handlernames" as a generic: class NamedHandler<H extends { [key: string]: HandlerFunction }> ...

utilizing a kendo component within a encapsulated template/component configuration

Can custom column definitions be transcluded through ng-content or TemplateRef in Angular? I've experimented with the Kendo UI Grid plunker available at the following site (http://www.telerik.com/kendo-angular-ui/components/grid/) as well as this Stac ...

Why does my useEffect consistently execute after the initial rendering, despite having specified dependencies?

const [flag, setFlag] = React.useState(false) const [username, setUsername] = React.useState('') const [password, setPassword] = React.useState('') const [errorUsername, setErrorUsername] = React.useState(true) const [er ...

What is the best way to make two buttons align next to each other in a stylish and elegant manner

Currently, I am diving into the world of glamorous, a React component styling module. My challenge lies in styling two buttons: Add and Clear. The goal is to have these buttons on the same row with the Clear button positioned on the left and the Add button ...

Obtaining a value from within an Angular 'then' block

I have a unique issue that I haven't been able to find a solution for on StackOverflow: Within an Angular 6 service, I am trying to call a function from another service using TypeScript. Here is the code snippet: Service1: myArray: Array<IMyInte ...

The error message "TypeError: this.subQuery is not a function" is displayed

Whenever I execute the tests using jest, I consistently encounter the error message TypeError: this.subQuery is not a function pointing to a specific line in the testModelDb.test.ts file. In the tests/jest.setup.ts file: import 'reflect-metadata&apos ...