Hi,
First off, I have been searching the forum and reading the docs and have not been able to determine if what I am doing is correct or if I’m missing something in the docs etc so I figured I would post here in the hopes I might get some guidance.
Task:
Like a few others, I am wanting to have a default login screen. A simple ‘token’ determines if they have already logged in and if so it will show the main screen, otherwise it will prompt them to enter their credentials.
Question:
The workflow is fairly basic and I have seen a few posts on the topic but its still a little fuzzy and while I have gotten something to work it seem a bit clunky like I’m not doing it right.
Essentially my code is like this
var app = new Framework7({
init: false,
root: '#app', // App root element
id: 'ConBop', // App bundle ID
name: 'Framework7', // App name
theme: 'auto', // Automatic theme detection
on: {
init: function () {
console.log('App initialized');
createLogin();
},
pageInit: function () {
console.log('shit')
},
}
NOTE: This was based off another answer I saw on the forum for a similar issue
All is good here, we see that things are setup and on the ‘init’ call the create login that looks like this
function createLogin() {
login_screen = app.loginScreen.create({ el: '.login-screen' });
// Close login screen
login_screen.open(false);
checkLogin();
}
Ok, so this calls the check login screen and then does a check, if there is a token, don’t show the login, however if their is a token show the login.
Again this works but where I feel things are clunky (for me anyhow) is that
-
If I don’t set init:false when I define the app the ‘app’ variable will be undefined. Obviously this is because its not finished initializing however I am calling the ‘createLogin’ function via the ‘on: init’ property of the app declaration so my assumption would be that the on:init would mean it has been initialized?
-
I understand the create login function can have an element that may be on a specific ‘page’ in this case the ‘index.html’ page however is their a way to route to a specific index page from the app.loginscreen.create? I didn’t see this option on the docs and I feel like this should be something that works however I did not see any working examples of this, instead only ways to use it as a ‘modal’ or a ‘button’ click page.
Again, I do have this working ‘as is’ but I wanted to just see if this is how I should be doing it or am I just missing something or not understanding etc.
Thanks for any help!