使用js.dart暴露auth0 API [英] using js.dart to expose auth0 API

查看:194
本文介绍了使用js.dart暴露auth0 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Dart编程的新手,所以请与我一起露面)。

I'm new to Dart programming so please bare with me :)

我在写一个DArt Angular2应用程序,但它与手头的问题无关。

I'm writing an DArt Angular2 application but it's irrelevant to the problem at hand.

我试图通过dart使用Auth0Lock,通过使用1https://pub.dartlang.org/packages/js公开其API。

I'm trying to use Auth0Lock with dart by exposing it's API using 1https://pub.dartlang.org/packages/js.

我正在使用Dartium调试应用程序。

I'm using Dartium to debug the application.

所以我使用下面的auth0lock.dart文件暴露Auth0Lock API: / p>

so I'm exposing the Auth0Lock API using the following auth0lock.dart file:

import 'package:js/js.dart';

@JS()
class Auth0Lock {
 external factory Auth0Lock(String token, String domain, Object options);
  external on(String event, Function func);
  external show();
}

我只暴露了我需要的基本东西。

I exposed only the basic stuff I need.

然后我在名为 auth0_service.dart 的文件中创建了一个Angular2服务,它具有以下代码:

then I created an Angular2 service in a file named auth0_service.dart that has the following code:

import'package:angular2 / core.dart';
import'auth0lock.dart';
import'app.config.dart';

import 'package:angular2/core.dart'; import 'auth0lock.dart'; import 'app.config.dart';

@Injectable()
class Auth {
Auth0Lock lock;

Auth() {
    this.lock = new Auth0Lock(configObj.auth0.apiKey, configObj.auth0.domain,{});
}
updateProfileName(data) {
  var profile = data['profile'] != null ? data['profile'] : data;
  print(profile['name']);
}

authenticated() {
  return false;
}

login() {
    this.lock.show().then(this.updateProfileName);
}


}



还会显示我加载auth0的 index.html

<!DOCTYPE html>
<html>
<head>
    <title>Demo App</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="www/styles.css">
    <script src="https://cdn.auth0.com/js/lock/10.0.0/lock.min.js"></script>
    <script defer src="/web/main.dart" type="application/dart"></script>
    <script defer src="/packages/browser/dart.js"></script>
</head>
<body>
    <my-app></my-app>
</body>
</html>

当我运行我的应用程序时,我得到以下错误:

when I run my application I get the ollowing error:

EXCEPTION: No static method 'Auth0Lock.' declared in class 'Auth0Lock'.

所以Auth0Lock不是一个静态方法,它是类的构造函数。因此我必须以某种方式使用JS api。

so Auth0Lock is not a static method, it's a constructor for the class. so I must used the JS api wrong somehow.

任何想法?

推荐答案

我需要在 auth0lock.dart 前面加上以下内容:

i need to prepend to the auth0lock.dart the following:

@JS()
library test;

其实我可以将 test 想要...我只需要添加js标签和库名称。解决了它。

actually I can rename test to anything I want... iI just need to add the js tag and library with a name. that solved it.

这篇关于使用js.dart暴露auth0 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆