-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Almost works #3
Comments
Hey @henrikra, please don't be mad at me, you're, most likely, the second user of this library. And I'm the first one. I'm not very experienced with Ampliy, so I might be doing something wrong, but this is how I get user session: import { Auth } from '@aws-amplify/auth';
(async () => {
const currentUser = await Auth.currentAuthenticatedUser();
if (currentUser === false) {
return;
}
const session = await Auth.userSession(currentUser);
})(); |
Thanks for the quick reply! And I am not mad :D I am using It is used like this. Can you also try if it works for you or not? import { CognitoUserPool } from "amazon-cognito-identity-js";
function main() {
const cognitoUserPool = new CognitoUserPool({
UserPoolId: "id_here",
ClientId: "id_here",
});
const currentUser = cognitoUserPool.getCurrentUser()
if (currentUser === null) {
return
}
// With Pontis currentUser.getSession is undefined
currentUser.getSession((error, session) => {
console.log('session', session)
});
}
main(); |
// web app
import { CognitoUserPool } from "amazon-cognito-identity-js";
import { AppAuthStorage } from '@vocably/pontis';
const cognitoUserPool = new CognitoUserPool({
UserPoolId: "id_here",
ClientId: "id_here",
Storage: new AppAuthStorage(chromeExtensionId),
}); // extension
import { CognitoUserPool } from "amazon-cognito-identity-js";
import { registerExtensionStorage } from '@vocably/pontis';
const cognitoUserPool = new CognitoUserPool({
UserPoolId: "id_here",
ClientId: "id_here",
Storage: registerExtensionStorage('sync'),
}); |
Yes I am but it is not working. Interesting 🤔 Would it be possible if you could create a new repo that has example web app and extension setup that works with Pontis? That would be beneficial to users of this library to see what kind of setup works 👍 You could link the example repo to the README of Pontis |
I'm sorry, I was wrong. I can't make my tests work with It seems like to make auth work on both app and extension, you'll have to call the // web app
import { CognitoUserPool } from "amazon-cognito-identity-js";
import { AppAuthStorage } from '@vocably/pontis';
const storage = new AppAuthStorage(chromeExtensionId);
storage.sync().then(() => {
const cognitoUserPool = new CognitoUserPool({
UserPoolId: "id_here",
ClientId: "id_here",
Storage: storage,
});
}); // extension
import { CognitoUserPool } from "amazon-cognito-identity-js";
import { registerExtensionStorage } from '@vocably/pontis';
const storage = registerExtensionStorage('sync');
storage.sync().then(() => {
const cognitoUserPool = new CognitoUserPool({
UserPoolId: "id_here",
ClientId: "id_here",
Storage: storage,
});
}); Or use |
Given the fact, React Native also uses async storage, the React Native example in the doc looks quite similar: var poolData = {
UserPoolId: '...', // Your user pool id here
ClientId: '...', // Your client id here
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
userPool.storage.sync(function(err, result) {
if (err) {
} else if (result === 'SUCCESS') {
var cognitoUser = userPool.getCurrentUser();
// Continue with steps in Use case 16
}
}); |
Thanks for the suggestion. Now I tried the trick to call Are you able to make small example repo so I can see if I am doing it correctly with |
@henrikra, I'm very very sorry it isn't working for you and I'd wish to dive deeper into the problem of why this library isn't working with |
I can try to make minimum reproduction repo for you 👍 Can you fix this more easier issue in the meanwhile? #2 |
@henrikra did you find a solution to this problem? |
Is it correct that the following code must run as content script on your web app? // website-app/index.js
import { Auth } from '@aws-amplify/auth';
import { AppAuthStorage } from '@vocably/pontis';
const extensionId = 'baocigmmhhdemijfjnjdidbkfgpgogmb';
Auth.configure({
// The following line sets up the custom storage
// which exchages auth tokens with the extension
storage: new AppAuthStorage(extensionId),
// and the rest of Auth params:
region: 'eu-central-1',
userPoolId: 'eu-central-1_uSErPooL',
//etc...
}); Otherwise, In this case, if one wants to access the authenticated user. e.g., to perform GraphQL requests, in the background worker, the popup script, or a content script from a different website, one would have to synchronize the Cognito credentials via the background worker? |
@bodokaiser , the |
@sneas I confused This insight allowed me to check if the messages are delivered by running The result was that actually,
|
Thank you for sharing your thought process and your discovery, @bodokaiser. The installation was quite obvious to me, but apparently, not very transparent to you, and most likely, other users. I will update the library documentation to make the installation process more straightforward. |
I am not sure the meaning of the website of your extension. |
Hi @noma6386-duplicate, you are right. The website/script.ts should be run on the website. Not on the content script. You redirect users to your website, authenticate them, and the lib passes token to the extension. Your website has to know the ID of the extension. This is how I solved this problem for Chrome and Safari extensions: https://github.com/vocably/vocably-pro/blob/main/packages/app/src/extension-id.ts |
I have setup extension and web site where I do the authentication like this library is saying. After login with my website the extension returns user when calling
cognitoUserPool.getCurrentUser()
which is correct. But the the returned user object's session is null. This means I cannot call for examplecurrentUser.getSession()
. Calling that function works in the website but not on the extensions service worker.Are you able to say if I am missing something or not?
The text was updated successfully, but these errors were encountered: