NextAuth Callback function in Google SignIn - async-await

I want to show notification after Google SignIn is done using signIn() function in NextAuth.js
googleSignInHandler is a function which is called when Google icon is clicked. In NextAuth.js, signIn is a function provided by next-auth/react. After successful login I want to show notification of successful login.
Following is the googleSignInHandler function
const googleSignInHandler = async () => {
await signIn('google', { callbackUrl: "http://localhost:3000" })
toast.success('Signed In Successfully!')
}
In signIn('google', { callbackUrl: "http://localhost:3000" }), after successful login, page is redirected to callbackUrl.
toast.success('Signed In Successfully!') displays notification of successful sign in.
I want to display notification when the sign in is done. But, as soon as googleSignInHandler is called, toast.success('Signed In Successfully!') gets executed immediately before signing in.
First of all, signing in should be done, then after redirection the notification should be showed. For this purpose, I think, there is need of callback function. Using await before signIn function does not help. I read the documentation but I didn't get any solution.

Related

NEW URL generated and cannot access to it

I have a process that create a quote divided in different test cases:
enter image description here
in the first IT I have the cy.visit which visit the login page of my page filling it with user and password
"the issue appears when I submit " I got a new URL generated and what I assumed is that it is not linking to the new url so the process stuck and cannot continue
enter image description here
so after that I got the error that the page cannot proceed, it stuck and get back to the login page and dont proceed with the other page generated automatically:
enter image description here
Well I am new in Cypress automation so I am not sure what is going on after I login on my page it get stuck in the process going back to the login page. So I am kind of sure it is not linking into the new URL that has the same domain so any person who has knowledge in Cypress can help me
It is the way Cypress works to stop one test contaminating the next one, and giving you a false pass.
The way you need to handle is with a session command to keep your login credential renewed for each test.
This is the pattern:
describe('before logged in', () => {
it("Login into the system", function () {
cy.visit(Cypress.env("ur146b"));
//login
login.getUser().type(this.data.user);
login.getPass().type(this.data.pass);
login.getLogin().click();
cy.wait(1000);
});
})
describe('when logged in', () => {
// now make such the login is renewed for each test
beforeEach(() => {
cy.session('login', () => {
cy.visit(Cypress.env("ur146b"));
//login
login.getUser().type(this.data.user);
login.getPass().type(this.data.pass);
login.getLogin().click();
})
})
it("Menu - full quote - get client", function () {
cy.visit('/homepage');
menu.getPolicy().click();
menu.getQuote().click();
menu.getClient().click();
cy.wait(1000);
});
it("fill client and address info", function () {
cy.visit('/homepage');
...
});
})
Read the complete details documentation page
Sorry I missed one step - it is mandatory to use cy.visit() in each test block after adding cy.session() to the login.
Otherwise you get the "blank page" problem you mention.
Ref session
Because the page is cleared at the beginning of each test by default, cy.visit() must be explicitly called at the beginning of each test.
enter image description here
I make the changes on my code also I added on cypress.config :experimentalSessionAndOrigin: true
enter image description here
I did my research and I got that the page is in blank and not showing the after login page

Xamarin Forms using FirebasePushNotificationPlugin plugin with Autofac and Shell unable to display UI elements nor redirects

I'm experiencing an issue that I've tried different ways to resolve and have been unsuccessful with. Whenever receiving a message via CrossFirebasePushNotification.Current.OnNotificationReceived I get the payload and can read it, but I can't do anything "visual" in my app. In other words, I get the notification but when I want to either redirect to another page or even display a DisplayAlert message, nothing happens. MessagingCenter can be received, but any instructions within the procedure that have to do with redirecting or DisplayAlert (anything changing the UI it appears) will not be executed.
Looking for help in how to visually show in the app the user has received a message.
This is in MainShell.xaml.cs (I've also placed it in App.xaml.cs too):
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
System.Diagnostics.Debug.WriteLine("Received"); // this works
foreach (var data in p.Data)
{
System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}"); // this works
}
//TODO: Code to determine if user is signed in
if (true)
{
System.Diagnostics.Debug.WriteLine("Debug: Goto Registration page from MainShell"); // this works
//Task.Run(async () => await Shell.Current.GoToAsync("registration")); // this does not work (just ignores it and doesn't fire constructor)
//Task.Run(async () => await Current.DisplayAlert("Request Received", "A message is waiting...", "Ok")); // this does not work
MessagingCenter.Send(this, "RequestReceived"); // this works, the receiver will display debug info, but will not redirect nor display any UI messages or interact with the UI.
}
};
Thank you for any help or guidance,
Robert

Oracle JET : Want to create a login page in which after click on login button should route me to home page

Hi I am using the example application with navigation list but I want to create a login page on top of it in which once I click login button and after authentication i have to route the application to main page.
I tried below code but nothing happened.
oj.Router.rootInstance.go('login');
please help.
Application : Oracle JET distribution
Code:
function (oj, ko, app) { // this callback gets executed when all required modules are loaded
$(function() {
function init() {
oj.Router.sync().then(
function () {
// Bind your ViewModel for the content of the whole page body.
ko.applyBindings(app, document.getElementById('globalBody'));
// navigate the user to login or wherever you want them to be now
oj.Router.rootInstance.go('login');
},
function (error) {
oj.Logger.error('Error in root start: ' + error.message);
}
);
}
You'll want to move your router go() commands out of the main.js and into a viewModel that backs the login page and only runs if and when the user passes your authentication test by entering the right username/password.
If login is the default page you want them to see, change the router.configure and navData setup in appController.js to make that the default page:
self.router.configure({
'login': {label: 'Login', isDefault: true},
...
Have a look at the FixItFast sample code for an example of a login page and the structure that supports it. FixItFast is a much more involved example than the standard Starter templates because it assumes mobile-first, but the signin.html view and signin.js viewModel might give you good ideas.
First you make your login page as default page.
Then (in your login.html) on button click you can call a function (function in login.js) where validation of your username and password takes .
self.signIn = function()
{
//your validation
if (login==success)
{
oj.Router.rootInstance.go('dashboard');
}
else
{
alert("check your details");
}
};
Make sure that you have add your dashboard page in router config
self.router.configure({
'dashboard': {label: 'Dashboard'},
'login': {label: '',isDefault: true}
});

Ember RSVP promise stopped working

For some reason an RSVP promise I created in an action stopped working for me and I can't figure out what when wrong where to make it stop working.
I have a component that sends an action and waits for a response
// COMPONENT IN ITEM ROUTE
callAjaxAction() {
this.setProperties({working:true});
Ember.RSVP.cast(this.attrs.action()).finally(() => {
Ember.$('.draggable').animate({
left: 0
});
this.setProperties({working:false});
});
}
This particular instance of the component calls this action in the controller
// IN ITEM CONTROLLER
placeBid() {
return new Ember.RSVP.Promise((resolve,reject) => {
if(this.get('winning')) {
this.get('notification')._confirm({message: "You are currently the highest bidder, would you like to continue with your bid?",isConfirm: true}).then(()=>{
console.log('confirmed');
this.send('placeBidActual').then(()=>{
resolve();
}).catch(()=>{
reject();
});
return true;
}).catch(()=>{
resolve();
console.log('denied');
return false;
});
} else {
setTimeout(()=>{
this.send('placeBidActual').then(()=>{
resolve();
}).catch(()=>{
reject();
});
},500);
}
});
}
This action is calling a confirm method on a service and waiting for the user to hit yes in the case of the user already winning this item. Otherwise I'm just calling the actual ajax action right away, that action looks like this
// IN ITEM CONTROLLER
placeBidActual() {
return new Ember.RSVP.Promise((resolve,reject) => {
Ember.$.ajax({
...
}).then((response)=>{
(do some stuff with the response)
resolve();
}, (reason)=>{
(do something with rejection reason)
reject(reason);
});
});
}
In the console I'm getting the error
Uncaught TypeError: Cannot read property 'then' of undefined
On the line where it states this.send('placeBidActual')
UPDATE:
Here is maybe a better explanation to the expected process flow.
The user attempts to place a bid, the user swipes a component over to indicate they wish to bid. The UI at this point shows a loading indicator and waits for the ajax action to complete before it resets the UI.
If the user is not already the highest bidder of the item it will go straight to the ajax action and upon completion signifies to the component to reset the UI.
However, if the user is the highest bidder of the item it should instead show a confirm message (using the notification service I have setup) and wait for the user to either confirm or deny. If they deny it just cancels and signifies to the component to reset the UI. If the user confirms then it calls the ajax action and upon completion signifies to the component to reset the UI.
Updated answer:
This isn't working because send doesn't return the value of the action.
I suggest moving the placeBidActual action to a method on the controller and call it like any normal method. This way you will get the return value and be able to call .then on it.
You should pass a function, whithout invoke it.
Instead this:
Ember.RSVP.cast(this.attrs.action()).finally(() =>
Try it:
Ember.RSVP.cast(this.attrs.action).finally(() =>
Invoking the funcion this.attrs.action() does it pass undefined for the Promise.

how to cancel fancybox from an AJAX callback within onStart

I am loading a login form within a fancybox. If the user has the site open in two browser tabs, and logs in in the first tab, and then clicks the login link in the second tab, I want to avoid opening the fancybox in the second tab since the page will redirect to the user profile and won't look good inside of the fancybox. So I have an AJAX callback within the onStart setting to check if the user is authenticated. If the user is already authenticated, I want to cancel the fancybox and direct the parent to another page (such as the user profile).
Here is my onStart code at the moment:
'onStart': function(opener) {
if ($(opener).attr('id') == 'login') {
$.get('/hicommon/authenticated', function(data) {
if ('yes' == data) {
console.log('this user must have already authenticated in another browser tab, SO I want to avoid opening the fancybox.');
return false;
} else {
console.log('the user is not authenticated');
return true;
}
});
}
},
This doesn't prevent the fancybox from opening for authenticated users, presumably because I'm returning false within the AJAX callback, rather than in the scope of the onStart function. Is there some way I can cancel the fancybox from within that AJAX callback, or pass something to the scope of the onStart function? Thank you

Resources