How to refresh page on expressjs - express

module.exports.deleteSession = function(req,res){
res.clearCookie('user_id');
return res.redirect('back');
}
This is my signOut code this will redirect to the signIn page.
but when I click on back button this will show previous page and when i click refresh button then this will delete the button and again showing the signIn page
So anyone give the solution to refresh the page automatically

Related

Deep Link from email covers react nativagtion

I have a scenario like this:
User reset his password by providing an email in RN App, Backend generates an Email with a reset link. Then the user clicks on Deep Link attached to Email Button
App is opening on the reset password screen, by Deep Link
User is setting a New password, then redirected to the login screen, when he makes a login by new password/email
THIS PART IS IMPORTANT
After a successful auth process, I'm Unmounting StackNavigation with authentication screens and mounting new StackNavigation with private routes.
When the user makes an logout a StackNavigator with auth screens is mounted again - RN automatically opens Screen from a deep link.
This is bad - Initial route from StackNavigation should be opened (and it is for few seconds)
Important note:
I've added Linking.removeEventListener("url");
Linking.getInitialURL() and Linking.addEventListener("url", () => { ... }); - are not invoked after logout

Google OAuth2 SignIn method fires at page load

I have used the official button for Google SignIn:
SignIn Page:
<div class="g-signin2" data-onsuccess="AuthenticateGoogleUser"></div>
function AuthenticateGoogleUser(googleUser){
.....
capture the user info and redirect to Home page
.....
}
When configuring for the credentials, I have set the redirection URL to the signin page.
This is how the Signout happens for the app:
function SignOutGoogleUser() {
if (gapi != null && gapi != undefined &&
gapi.auth2 != null && gapi.auth2 != undefined) {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
auth2.disconnect();
....Redirect to Home page...
});
}
}
The methods work fine. If I signout, will be redirected to home page.
But, when I manually browse the SignIn page after signout, the AuthenticateGoogleUser method is triggered and I am auto signed into the app (with google account).
The AuthenticateGoogleUser method should be only triggered on the button click. Is that right.
But here it is being triggered on load of SignIn page. Is that expected. Can this be stopped.
I'm using MVC C# as backend.
Without seeing all of your code, I am working on the assumption that you have not placed the function in a document ready wrapper and made sure to only kick it off on a button click or other event from which you would like to have it fire. As it stands now, it will fire on that page load.
$(document).ready(function(){
$("btnLogin").click(function(){
AuthenticateGoogleUser(googleUser);
});
});

Handling device back button in react native

I am handling the Android back button in React-Native using BackHandler in home page its working fine, when i navigate to home page from login page. But when i go to page 2 from home page and came back to home page by clicking the device back button, now when i click device back button in home page its taking me to login page, this should not happen.
Navigation used in home page is a drawer navigation.
I am removing the backpress event handler when i am navigating to page2, because it is disabling the back button in page 2 also.
You just have to implement the Backhandler in your home page, and don't perform any action on it.
BackHandler.addEventListener('hardwareBackPress', () => {
return false
});
Just return false. So It won't navigation to Login screen again.

React Native Stacknavigator, run code before going back

Say there are two screens: screenA, screenB; these are managed using StackNavigator.
User clicks on a button in screenA that navigates the user to screenB. ScreenB has a form where they can edit their name, username, and more. I want to make it so that, after the user edits their personal information by editting the default values of TextInput in screenB, the user can just either click the backbutton in the navigation header or swipe left on the screen to return back to screenA.
In that process of returning back to screenA, I want to have a loading circle and not allow the user to return back to A until the the user receives confirmation from the API endpoint that edits the user's personal information that it worked.
User edits information on screenB.
User tries to navigate back to screenA by either clicking the back button in the header or by swiping right.
A loading circle appears, indicating that the app has sent a request to the API to edit their information accordingly. The user has not navigated to screenA at this point.
Request is successful, and the user is taken to screenA.
For me to do this, I need to be able to add some sort of function to the going back navigation that lets me do all this. Does anyone know how I can do this?
NOTE: I've already looked into writing my custom button for the backbutton but that still doesn't solve the problem of swiping right to navigate.
Please provide us with your code so that we can help better, what you need is an async function. Something like this:
async UploadInformation(username, password) {
let response = await fetch(url,{
method: method,
body: JSON.stringify({
'username':username},
'password':password),
headers: headers
});
return response;
}
Then in your backbutton
async back_button(){
//show your loading indicator
let r=await UploadInformation(this.username, this.password);
//remove your loading indicator
this.props.navigation.navigate('A');
}
By using async and await you are telling react to wait for the function to finish its job.

Google+ signout without dialog popup

I have a signout button on my page that I'm initiating this way:
$('#logout').click(function() {
gapi.auth.signIn({
'callback': function(authResult) {
if (authResult['status']['signed_in']) {
gapi.auth.signOut();
} else {
// second pass, signout succesful
}
}
})
});
This ends up making two calls out to Google (first to validate that user is already logged in, second to sign out), thus the two passes through the callback code. This also causes the Google+ login window to briefly popup.
Is there a way to just call gapi.auth.signOut() directly without the signIn step? I have the user's Google+ id (and also access_token), if that helps.
You don't need to call the gapi.auth.signIn() every time you want to sign out. just call the gapi.auth.signOut() from anywhere to initiate the sign-out process from your app (but still signed in to Google in other tabs, which is good practice).
Example would be to just attach the gapi.auth.signOut() event to an onclick event on a button;
<button onclick="gapi.auth.signOut();">Sign out</button>