Skip to content

Commit

Permalink
Add route guard
Browse files Browse the repository at this point in the history
  • Loading branch information
meghanmae committed May 28, 2024
1 parent 2114f58 commit 82ce612
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
14 changes: 14 additions & 0 deletions wordle-web/middleware/auth-middleware.global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import TokenService from "~/scripts/TokenService";

export default defineNuxtRouteMiddleware((to, from) => {
const tokenService = new TokenService();

console.log("here");
switch (to.path) {
case "/test":
if (!tokenService.isLoggedIn()) {
return navigateTo("/403");
}
break;
}
});
23 changes: 23 additions & 0 deletions wordle-web/pages/403.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<v-container class="d-flex justify-center align-center">
<v-row>
<v-col cols="12" class="text-center">
<v-icon large class="mb-4">mdi-alert-circle-outline</v-icon>
<h2 class="display-2">403 | Forbidden</h2>
<p class="subtitle-1">You do not have permission to access this page.</p>
<v-btn color="primary" @click="goHome">Go Home</v-btn>
</v-col>
</v-row>
</v-container>
</template>

<script setup>
import { useRouter } from 'vue-router';
const router = useRouter();
const goHome = () => {
router.push('/');
};
</script>

0 comments on commit 82ce612

Please sign in to comment.