У меня есть собственное приложение (без expo), которое называется myapp.
У меня есть собственный пакет под названием myapp-core, в котором я работаю со службами AwsAmplify (Auth, Storage) - для входа в систему или входа в систему./etc.
Я хочу использовать myapp-core в проекте myapp, поэтому я добавил его в качестве зависимости в package.json
("myapp-core": "file:../myapp-core",
), а затем yarn install
.
ПроблемаЯ сталкиваюсь с тем, что, когда я звоню myapp-core.authService.login(username, password)
из мобильного проекта, я улавливаю ошибку:
«{« line »: 177826,« column »: 17,« sourceURL »:«http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false”} ”
Из моего исследования это означает, что моя пользовательская библиотека не может выполнять вызовы API - но я точно не знаю.
Когда я использую aws-Усилить объект Auth прямо в моем мобильном проекте, он работает.
Надеюсь, соответствующий код:
/**=============================**/
/** myapp/CoreServices.js **/
import { AmplifyService } from “myapp-core";
export default class CoreServices {
constructor() {
AmplifyService.configure();
const auth = AmplifyService.authService();
auth
.login(“myusername”, “mypassword”)
.then(user => console.warn("success", user))
.catch(error => console.warn("error", error));
}
}
/**=============================**/
/** myapp-core/AmplifySevice.js **/
import Amplify from 'aws-amplify';
import AuthService from '../AuthService/AuthService';
import awsConfigs from '../aws-exports';
class AmplifyService {
static authServiceInstance = null;
static storageServiceInstance = null;
static configure(config = awsConfigs) {
if (config === null || config === undefined) {
throw new Error('AmplifyService must be initialized with Auth and Storage configurations.');
}
Amplify.configure({
Auth: { /*...*/ },
Storage: { /*...*/ }
});
}
static authService() {
if (!this.authServiceInstance) {
this.authServiceInstance = new AuthService();
}
return this.authServiceInstance;
}
static storageService() {
console.warn('storage service');
// initialize storage service
// return storage service
}
}