Magento2 Addtocart success msg disappear - message

After clicked the add to cart button success message disappear while detail page and list page.
I have used some code changes for messages.js
$.cookieStorage.setConf({path: '/', expires: -1}).set('mage-messages', null);
That's also not working.
Any one give suggestion magento2.4 success message flashout immediately.
I want success msg load properly after addtocart.

Related

Why does apostrophe keep making POST calls to check if user logged in?

There are a bunch of POST calls from the website to the server and I don't know how to turn them off.
2019-10-24T21:24:49.606Z - info: admin already logged in. Passing through...
2019-10-24T21:25:09.767Z - info: /modules/apostrophe-notifications/poll-notifications
2019-10-24T21:25:09.768Z - info: admin already logged in. Passing through...
2019-10-24T21:25:29.911Z - info: /modules/apostrophe-notifications/poll-notifications
2019-10-24T21:25:29.912Z - info: admin already logged in. Passing through...
2019-10-24T21:25:50.023Z - info: /modules/apostrophe-notifications/poll-notifications
2019-10-24T21:25:50.024Z - info: admin already logged in. Passing through...
That just keeps going on and on...
In my app.js file, I've set the longPollingTimeout options to 0, but it doesn't stop it, and when I set it to 20000 ms it sends it every 20 seconds.
var apos = Mongo.getMongoPw().then(function(mongoPw){
return require('apostrophe')({
...
modules: {
...
'apostrophe-notifications': {
longPollingTimeout: 20000
},
...
}
});
It seems very pointless and spammy in my logs which we send to splunk.
How can I turn this off if it's unnecessary?
The API you're referring to is polling for notifications, which can be sent at any time by server-side or browser-side code. For instance, if you try this in the browser console:
apos.notify('Oh no!', { type: 'error' });
You'll get a notification, which persists until dismissed (it's stored server-side).
Where this gets more useful is when they are sent on the server side. For instance, your server-side javascript may also say:
if (req.user) {
// server side you must include req
apos.notify(req, 'Oh no!', { type: 'error' });
}
Now a notification will reach the currently logged-in user, sooner or later, and you don't have to think about how to deliver it; it just gets taken care of for you by poll-notifications. This is very useful in long running tasks. Without this feature enabled Apostrophe would be unable to deliver many necessary messages to the user.
However, you're wondering why you get this annoying message in your logs:
admin already logged in. Passing through...
I have checked both the apostrophe core module and the apostrophe workflow module. Neither contains any such message. I have also used github search to check the entire apostrophecms organization for this message, which does not appear. Same for a github-wide search. I left out the word "admin" and, in the apostrophecms org, also tried a search for "passing through" alone without turning up any code.
So what this indicates is that your custom code, or another npm module you have added to your project, contains custom middleware that is logging this message on every request that comes in. I would recommend quieting that middleware down as it's not necessary to report this on every notification poll.

Slack deep link into client: how to link into im if im not open

I made a platform-independent contactlist-style standalone client for Slack in Qt/C++.
It uses Slack's Deep Linking scheme to navigate through the official Slack-Client when clicking Items in my ContactList.
The problem is, when clicking a user item in my list (which gets the user id and creates the link), the slack client will only enter the im dialog, if it was open before (if i have a im history with that user).
Otherwise it will just show the team directory context for that user, where i manually have to click "message" to actually enter the chat dialog.
Is there really no way to do it right just with slack:// deep links?
The only solution that i can think of right now is to open a new im, if not exist, using api call from my application before opening the link. or maybe open im's for all users at app launch.
But that's kind of a dirty workaround, that i don't like.
Is there a more elegant way to go directly to a new IM than this?
EDIT: quick Workaround without error handling is working this way:
void Window::contactListDoubleClicked(QTableWidgetItem *item)
{
QString id = listWidget->item(item->row(),1)->text();
int type = listWidget->item(item->row(),3)->text().toInt();
if (type == 1) { // if item is a user, we have to ensure that im exists by requesting im.open
QEventLoop eventLoop;
QNetworkAccessManager mgr;
QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QNetworkRequest req(QUrl(QString("https://slack.com/api/im.open?token=").append(m_token).append("&user=").append(id)));
QNetworkReply *reply = mgr.get(req);
// block stack until reply is ready
eventLoop.exec();
qDebug() << reply->readAll();
QDesktopServices::openUrl(QUrl(QString("slack://user?team=XXXXXXXX&id=").append(id),QUrl::TolerantMode));
} else {
QDesktopServices::openUrl(QUrl(QString("slack://channel?team=XXXXXXX&id=").append(id),QUrl::TolerantMode));
}
}

How to detect that the current request is an authentication callback?

I have a single-page JavaScript application and I'm using the Auth0 service for signup/login.
I have integrated the Lock widget and I'm saving a string to localStorage after a user is authenticated, like so:
lock.on("authenticated", function(authResult)
{
localStorage.setItem('login', authResult.idToken);
}
The problem is that when Auth0 redirects them back to my application after logging in, the authenticated event is fired only after page loaded, but by that time, I've already done the check to see if the localStorage string is set (which it is not); therefore, the user just keeps getting asked to login again:
if(localStorage.getItem('login') == undefined)
{
lock.show(function(err, profile, token)
{
// ...
}
}
I tried to see if there was anything special passed in to the page after a callback - but the referrer isn't always there.
If I don't automatically prompt the user to login, but instead show a login button - the authenticated event never fires for some reason.
How do I get around this?
Based on the information provided you seem to be using Lock in redirect mode and if that's the case you can use the hash_parsed event as a way to know if Lock found a response that it will process.
Every time a new Auth0Lock object is initialized in redirect mode (the default), it will attempt to parse the hash part of the URL, looking for the result of a login attempt. After that, this event will be emitted with null if it couldn't find anything in the hash. It will be emitted with the same argument as the authenticated event after a successful login or with the same argument as authorization_error if something went wrong.
Leveraging this event you could do the following:
Subscribe to the hash_parsed event:
If hash_parsed is emitted with null and localStorage has no indication the user already logged in then redirect to login.
If hash_parsed is emitted with a non-null value that either the authenticated or authorization_error will be emitted and you can react accordingly.
Some sample code:
lock.on("hash_parsed", function (response) {
if (!response && !localStorage.getItem('login')) {
// Redirect to the login screen
} else {
// Either the user is already logged in or an authentication
// response will be processed by Lock so don't trigger
// an automatic redirect to login screen
}
});

Update database record after user has logged in

What I'm trying to achieve is similar to how the login works here on StackOverflow. If you are not logged in you can still see questions but if you try to +1 some of the questions you are asked to login. When you do login your +1 is remembered and added to the question.
This is my scenario:
A user search for members and selects one - login is not required
After selecting a member the user is redirected to a feedback page where the user can write a feedback message to the member
The user writes the feedback and click Save
No matter if the user is logged in or not the feedback is saved
If the user is not logged in a popup will open where the user will be asked to login
After the user logs in the feedback, created in step 4, will be updated with the user's Id
The user is redirected back to the search page from step 1
I'm stuck at step 6. I can't figure out what the best way of getting the Id of the logged in user and then update the feedback message after that.
This code represents step 5. It simply sends the feedback message to the controller and saves it. After the message is .done I call the login popup. The return message.Data contains the Id of the feedback message (which just has been created) and which I need after the user logs in.
function saveModel(feedbackMessage) {
cc.Ajax.jpost(urlSave, { feedbackMessage: feedbackMessage })
.done(function (message, textStatus, jqXHR) {
if (message.Status == 2) { // user not logged in
openSignInModal(message.Data);
}
})
}
This code represents step 6. The returned data is a partial view containing the login page.
function openSignInModal(feedbackId) {
var url = '/Account/LoginPartial';
$.ajax({
url: url,
type: 'get',
data: { returnUrl: '/Subscriber/Search', subTitle: feedbackNotSignedIn, modalTitle: '' },
success: function (data, textStatus, jqXHR) {
$('#pc_modal_container').html(data);
$('#pc_modal').modal('show');
},
});
}
If the user logs in then I want to get the Id of the user and update the feedback message with the logged in user's id (similar to what I explained in the beginning with StackOverflow).
My questions are:
Where should I keep the feedback message Id which I get in step 4 so I can use it to update the feedback message?
When the user is logged in and I want to update the feedback message how can I handle this best? I know I could store it in TempData but I don't really see this at the best option, or is it?
I have tried to find examples online but nothing that fits this well enough. Does anyone know of any examples which could fit this scenario?
Thanks
Try this process. It do not have any technical detail, but I believe it will be enougth to accomplish your goal.
During the feedback POST, preserve the feedback post ID into a Cache variable, as PendingFeedBacks
Make these cached data availabe only to current session, and with low expiration period
Somewhere, if the user is authenticated, and there is any pending feedback to be adopted, do it!
I do not believe that this should be the best solution, but it will do the trick.

jQuery: Continue custom click event on successful ajax login

I have a set of links (add to wishlist) with click event . The click event checks if the user is logged in (ajax request) and depending on the result the click continues. In the case the user is not logged in I have a generic jQuery UI modal dialog that the user can use to log in.
That all works well but I would like to extend the functionality to be able to continue with click of the links after the user logs in using the dialog.
ie. CLICK ADD TO WISHLIST -> LOGGED IN ?
YES -> CONTINUE LINK CLICK (add to wishlist)
NO -> SHOW LOGIN DIALOG ->
USER SUBMITS CREDENTIALS -> LOGGED IN?
YES => CONTINUE LINK CLICK (add to
wishlist)
NO => SHOW LOGIN ERROR
Of course I do not want to perform any postbacks, all through ajax and jquery.
Thanks
You could pass the url of the click action to the login modal and redirect after successful login.
Alternativly, if you have set it up to login via AJAX, you could store the click event target and then trigger a click event after a successful login.
Something like the following:
var is_logged_in = false;
$('a.add_to_wishlist').click(function(e) {
if(is_logged_in) {
//do stuff
} else {
show_modal(e.target); //pass the event target to the modal
}
});
function show_modal(trigger) {
//do stuff
is_logged_in = true;
$(trigger).trigger('click');
}
Hopefully this helps.
If you're in control of your server side code then you should place the authentication + save to wish list in the same request.
User clicks add to wish list
Ajax request to add page to wish list is sent to server.
Server check to see if user is logged in.
If the user is logged in: save the item to the wish list and return a success response.
If the user it not logged in: return a failed response.
The ajax response callback should update the UI based on the response.
If you're not in control of your server code then you'll have to make two ajax request if the authentication request is successful.

Resources