Closed Neptunium1129 closed 1 year ago
It's very hard for me to help without seeing more context.
What I'd normally recommend is to use route pre-conditions to redirect users to your #login endpoint if needed: https://github.com/ItalyPaleAle/svelte-spa-router/blob/master/Advanced%20Usage.md#route-pre-conditions
app.svelte is branched for three conditions: customer, developer, and external developer. However, I thought that it is not suitable for preconditions because it only applies to true or false.
'/': wrap({
asyncComponent: () => import("./components/work/main.svelte"),
userData: {
hello: 'world',
foo: 'bar',
myFunc: () => {
console.log('login do something!');
}
},
conditions: [
// First pre-condition function
async (detail) => {
let result = false;
console.log("Pre-condition 1 executed : ", detail);
//session check
debugger;
await api.post("login/loginCheck", "", null).then((res)=>{
console.log(res);
if(res.data.responseMessage=="FAIL"){
result = false;
}else{
result = true;
userSession.set(res.data.data);
}
})
// Pre-condition succeeds only 50% of times
return result;
},
]
}),
You can return false from the condition function, then listen to the “conditionFailed” event to redirect the user (use the replace() method from this router)
Thansk!
If there is no way, I want to find an alternative.