Ionic 2 show login page over slide menu app - authentication

Q) How to I show a login page over the top of my standard slide menu app in Ionic 2?
My slide menu app is up and running, I just need that initial login page setup correctly.
Things I know:
How to show a modal page with nav.present().
How to dismiss a modal page.
Things I DON'T know:
Where to instantiate + show this page
How to have it accessible from any current page (i.e. if the user is logged out)
Note: this is for Ionic 2, not 1. I know there are many examples of this in Ionic 1, but they're not applicable thanks.
Any ideas? Thanks.

Solved: Using event listeners as follows:
1.) I have added a LoginPage to my app.ts:
import {Events} from 'ionic-framework/ionic';
import {LoginPage} from './pages/login/login';
Then, I made it the rootPage:
class MyApp {
rootPage: Type = LoginPage;
2.) Then, I register some listeners:
ngOnInit() {
this.subscribeToEvents();
}
ngOnDestroy() {
this.unsubscribeToEvents();
}
subscribeToEvents() {
this._events.subscribe('login:success', () => {
this.getNav().setRoot(TodosPage);
});
this._events.subscribe('logout:success', () => {
this.getNav().setRoot(LoginPage);
});
}
unsubscribeToEvents() {
this._events.unsubscribe('login:success', null);
this._events.unsubscribe('logout:success', null);
}
getNav() {
return this.app.getComponent('nav');
}
3.) Then, in my LoginPage:
<button full (click)="login()">Login</button>
login() {
// Do some auth here first...
this._events.publish("login:success", null);
}

Related

How do I set a fallback path/route with vueRouter if the navigation goBack ( < ) takes the user out of myb page?

I'm quite new with Vue, and vue-router. Right now I'm working on a page where we organize tennis matches, I have this component called goBack, it basically checks your browser history entries and take you back to the previous one, similar to the back-arrow in your browser. So I have this behavior which I don't like, and I don't know how to change it => if I set match, pass you the URL, if you enter and click on my goBack Comp it will take you out of my page. I want to avoid that with this logic, if your last browser history entry is not inside my page I want to redirect you to my home.
Here's the goBack component code:
setup(props, { attrs }) {
const router = useRouter()
const { t } = useI18n()
const goBack = (): void => {
if (attrs.onClick) return
if (router.options.history.state.back === null) {
router.replace('/')
} else {
router.back()
}
}
return {
t,
goBack
}
}
})
</script>
Thank you!

show modal when network is offline in ionic 4

I want to display a modal when the network connection is offline.
i have this working function that says to me when the network is online or offline:
verifyNetworkConnection() {
this.networkService.isNetworkConnected
.pipe(distinctUntilChanged())
.subscribe(connected => {
if (connected) {
console.log('Online!');
} else {
console.log('Offline!');
this.screenService.createModal(LostConnectionComponent);
}
});
}
when the conncetion is offline, i want to display a modal, but i got this error in my console:
GET http://localhost:8100/0.js net::ERR_INTERNET_DISCONNECTED
GET http://localhost:8100/164.js net::ERR_INTERNET_DISCONNECTED
why i cant open a modal when its offline?
this is my create modal function:
public async createModal(component, componentProps?) {
const modal = await this.modalCtrl.create({
component,
componentProps
});
return await modal.present();
}

How to program React-native-navigation nav bar back button (not hardware button)?

Im using Wix's react-native-navigation library. I'm trying to disconnect a socket connection when the Navigation bar back button is pressed or a swipe is used to move back to the previous screen. Not the hardware back button press on android.
I've followed Wix docs for handling button presses for top bar buttons, located here: https://wix.github.io/react-native-navigation/#/docs/topBar-buttons?id=handling-button-press-events
export default class Lobby extends React.Component {
static options(passProps) {
return {
topBar: {
leftButtons: {
id: "backButton"
}
}
};
}
constructor(props) {
super(props);
this.state = {
username: "",
queue: []
};
Navigation.events().bindComponent(this);
}
// as a parameter ive tried: {backButton}, "backButton", {buttonId}, and backButton
navigationButtonPressed(backButton) {
const socket = io("http://172.31.99.250:3000");
socket.emit("leaveLobby", this.state.username);
}
...
}
Firstly please make sure your clicking on button really works. Make same corrections to you code:
Add some icon image to your new button so that you really have something to click (insert some icon.png image in the same folder as your script is):
topBar: {
leftButtons: {
id: "backButton",
icon: require('icon.png') // <-- icon.png image
}
}
Then to your button action add simple alerting for instance:
navigationButtonPressed({ buttonId }) {
//const socket = io("http://172.31.99.250:3000");
//socket.emit("leaveLobby", this.state.username);
alert("Button tapped: " + buttonId) // <- In the alert box on your app you will see your button id, here "backButton"
}
If you see alert on your app but socket not disconnecting - you should do some more debugging on your socket.io implementation. Here for example I think you are creating new socket instead of disconnecting the one that already exists. I think you should import const socket from the other script where you are creating it.

Not Able to Logout from Login WebView (ADLoginView)

In React-Native Application I have implemented Microsoft's AD Login Functionality by using react-native-azure-ad#0.2.4".
Getting trouble while Logout from Microsoft's Account. When I trigger Logout First LoginView.js get rendered and then ADLoginView(WebView) redirects to Microsofts Login Page where upon entering new user id the app is taking me back to old logged out user login. [Basically previous users token is stored and I am not able to clear that]
See The below ScreenShot
/ ** Login.js **/
let needLogout
export default class Login extends Component {
constructor(){
super()
this.state = {
logout : false
}
new ReactNativeAD({
client_id: CLIENT_ID,
authority_host: 'https://login.windows.net/common',
redirect_uri: 'http://xxz.myappdomain.biz',
resources: [
'https://graph.microsoft.com',
]
})
context = ReactNativeAD.getContext(CLIENT_ID)
}
componentDidMount(){
needLogout = () => this.needLogoutSetFalse()
EventBus.addEventListener("Logout", needLogout);
}
render(){
return(
<ADLoginView
context={context}
onSuccess={this.onLoginSuccess.bind(this)}
hideAfterLogin = {true}
needLogout = {this.state.logout}
/>)
}
onLoginSuccess(credentials){
//Call The graph API and Navigate to Next view
}
needLogoutSetFalse(){
EventBus.removeEventListener("Logout", needLogout)
ReactNativeAD.removeContext(CLIENT_ID)
// By Setting needLogout true Webview will redirect to n . Microsoft’s official login page.
this.setState({logout: true})
}
}
/** Logout.js **/
onClickLogOut(){
// Will Clear Entire Async Storage.
userInfo.removeUser().then(()=>{
// Will Navigate to Login Page
this.props.navigation.dispatch(resetAction)
// Invoke the needLogoutSetFalse method from Login.js.
EventBus.dispatch("Logout")
Toast.show('Log out successful')
})
}
It works check the below link,
https://github.com/wkh237/react-native-azure-ad/issues/21#issuecomment-322645856

How can I share text on a Windows 10 App?

I am building a Windows 10 Web App by Project Westminster. I want to create a button to invoke the native share capability, sharing some text I have. I have the below codes. Clicking on my button would call the share() function.
function share() {
Windows.ApplicationModel.DataTransfer.DataTransferManager.showShareUI();
}
function shareTextHandler(e) {
var request = e.request;
request.data.properties.title = "Share Text Example";
request.data.properties.description = "Demonstrates how to share.";
request.data.setText("Hello World!");
}
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// This app is newly launched. Register the app as share source.
var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
dataTransferManager.addEventListener("datarequested", shareTextHandler);
} else {
// TODO: This app was reactivated from suspension.
// Restore the app state here.
}
args.setPromise(WinJS.UI.processAll());
}
};
But now when I click on the button, it will share the screen captured on my app, not the text I intended to share. How can I correct the behaviour? Thanks!