我正在尝试实施此自定义登录auth0 service,但我遇到了导入问题。我的麻烦在于declare var auth0: any
。每当我尝试,我得到:
EXCEPTION: Uncaught (in promise): ReferenceError: auth0 is not defined
问题是,我尝试使用declare var Auth0Lock: any
webpack.config.js
使用// Configuration in 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, if enabled, 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 running in 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 that apply in production builds only
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin()
])
});
// Configuration for server-side (prerendering) bundle suitable for running in 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
});
//var authBundleConfig = merge(sharedConfig, {
// entry: "../../node_modules/auth0-js/src/index.js",
// output: {
// filename: filename.join(__dirname, 'build.js')
// },
// module: {
// loaders: [{
// test: /\.js$/,
// exclude: /(node_modules|bower_components)/,
// loader: 'babel'
// }]
// }
//});
module.exports = [clientBundleConfig, serverBundleConfig/*, authBundleConfig*/];
来做到这一点。我正在使用.NET Core + Angular2解决方案,该解决方案使用webpack进行编译。我不确定是否必须向authBundle
添加内容,但现在是:
// 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;
//declare var auth0: any;
@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) {
}
...
正如您所看到的,我尝试添加public class StudentRecord
{
private int quiz1;
private int quiz2;
private int midterm;
private int test;
private double finalpercent;
private char finalgrade;
public StudentRecord()
{
quiz1 = null;
quiz2 = null;
midterm = null;
test = null;
}
public StudentRecord(int t, int m, int q1, int q2)
{
quiz1 = q1*10;
quiz2 = q2*10;
midterm = m;
test = t;
}
public void setTest(int t)
{
test=t;
}
public void setMidterm(int m)
{
midterm=m;
}
public void setQuiz2(int q2)
{
quiz2=q2*10;
}
public void setQuiz1(int q1)
{
quiz1=q1*10;
}
public void setFinalPercent(int quiz1, int quiz2, int midterm, int test)
{
finalpercent = ((quiz1+quiz2)/2)*.25+midterm*.25+test*.5;
}
public void setFinalGrade(double finalpercent)
{
if (finalpercent => 90) THIS IS WHERE THE ERROR happens
{
finalgrade = A;
}
else if (finalpercent<=89&&finalpercent=>80)
{
finalgrade = B;
}
else if {finalpercent<=79&&finalpercent=>70}
{
finalgrade = C;
}
else if {finalpercent<=69&&finalpercent=>60}
{
finalgrade = D;
}
else
{
finalgrade = F;
}
}
public int getQuiz1()
{
return quiz1;
}
public int getQuiz2()
{
return quiz2;
}
public int getMidterm()
{
return midterm;
}
public int getTest()
{
return test;
}
public double getFinalPercent()
{
return finalpercent;
}
public char getFinalGrade()
{
return finalgrade;
}
public void inputinfo(Scanner.inFile)
{
private
}
}
,但这不起作用。
我的服务:
public class StudentRecordDriver
{
public static void main(String[] args)
{
Scanner inFIle = null;
try
{
inFile = new Scanner(new File("349f.txt"));
}
catch (FileNotFoundException e)
{
System.out.println("File not found");
System.exit(0);
}
System.out.pritnln("Studet\tQuiz1\tQuiz2\tMidTerm\tFinal\tFinal%\tGrade");
int student = 1;
while (inFile.hasNext())
{
String[] grades = inFile.nextLine().split(" ");
int quiz1 = Integer.valueOf(grade[0]);
int quiz2 = Integer.valueOf(grade[1]);
int midterm = Integer.valueOf(grade[2]);
int test = Integer.valueOf(grade[3]);
StudentRecord Student = new StudentRecord(int test, int midterm, int quiz1, int quiz2);
System.out.println(student+"\t"+student.getQuiz1+"\t"+student.getQuiz2+"\t"+student.getMidterm+"\t"+student.getTest+"\t"+student.getFinalPercent+"\t"+student.getFinalGrade);;
}
}
}
任何帮助表示感谢。
答案 0 :(得分:2)
我通过npm安装最新auth0-js typings
并在我的import * as auth0 from 'auth0-js';
中使用auth.service
,让导入工作。