Skip to content

Commit

Permalink
Fix dynamic import paths, redirect login -> Home (#43)
Browse files Browse the repository at this point in the history
* fix dynamic imports + redirect user to home route

* match all routes
  • Loading branch information
leigh-johnson authored Nov 6, 2022
1 parent 8221054 commit 957e53e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ async fn main() -> Result<()> {
warn!("Version: {}", GIT_VERSION);
HttpServer::new(move || {
let generated = generate();
App::new().
service(get_version_data::get_version_data).
service(ResourceFiles::new("/*", generated).resolve_not_found_to_root())
App::new()
.service(get_version_data::get_version_data)
.service(ResourceFiles::new("/*", generated).resolve_not_found_to_root())
})
.workers(config.workers)
.bind((config.host, config.port))?
Expand Down
7 changes: 7 additions & 0 deletions ui/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ router.afterEach((_to, _from) => {
router.beforeEach(async (to, _from) => {
const cloud = useCloudStore();
await cloud.fetchUser();

// redirect unauthenticated users
if (
// make sure the user is authenticated before proceeding to dashboard
!cloud.isAuthenticated &&
Expand All @@ -26,6 +28,11 @@ router.beforeEach(async (to, _from) => {
// redirect to login
return { name: "login" };
}

// redirect authenticated users home
if (cloud.isAuthenticated && to.name == "login") {
return { name: "Home" }
}
});

export default router;
8 changes: 4 additions & 4 deletions ui/src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ const TopBarRoutes = [
path: "/",
name: "Home",
components: {
default: () => import("../views/HomeView.vue"),
default: () => import("@/views/HomeView.vue"),
TopNav: TopNav,
},
},
{
path: "/vision",
name: "PrintNanny Vision",
components: {
default: () => import("../views/VideoView.vue"),
default: () => import("@/views/VideoView.vue"),
TopNav: TopNav,
},
},
Expand All @@ -25,14 +25,14 @@ const AllRoutes = [
path: "/login",
name: "login",
components: {
default: () => import("../views/LoginView.vue"),
default: () => import("@/views/LoginView.vue"),
},
},
{
path: "/settings",
name: "Settings",
components: {
default: () => import("../views/SettingsView.vue"),
default: () => import("@/views/SettingsView.vue"),
TopNav: TopNav,
},
},
Expand Down

0 comments on commit 957e53e

Please sign in to comment.