-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(frontend) redirect once user is logged to the homepage
- Loading branch information
1 parent
b17ca32
commit 78288f4
Showing
6 changed files
with
146 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
<!-- Home.vue --> | ||
|
||
<template> | ||
<div class="container"> | ||
<h1>Welcome to the Home Page</h1> | ||
<p>You are logged in as {{ userEmail }}</p> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, computed } from 'vue'; | ||
import { useAuthStore } from '@/store/auth'; | ||
|
||
export default defineComponent({ | ||
name: 'Home', | ||
setup() { | ||
const authStore = useAuthStore(); | ||
|
||
const userEmail = computed(() => authStore.userEmail); | ||
|
||
return { | ||
userEmail, | ||
}; | ||
} | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
/* Add your scoped styles for Home */ | ||
</style> | ||
|
||
<div class="container"> | ||
<h1>Welcome to the Home Page</h1> | ||
<p>You are logged in as {{ username }}</p> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, computed } from 'vue'; | ||
import { useAuthStore } from '@/store/auth'; | ||
|
||
export default defineComponent({ | ||
name: 'Home', | ||
setup() { | ||
const authStore = useAuthStore(); | ||
|
||
const username = computed(() => authStore.username); | ||
|
||
return { | ||
username, | ||
}; | ||
} | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
/* Add your scoped styles for Home */ | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,55 @@ | ||
<!-- Login.vue --> | ||
|
||
<template> | ||
<div class="container"> | ||
<h1>Login</h1> | ||
<form @submit.prevent="login"> | ||
<div> | ||
<label>Username:</label> <!-- Change label to Username --> | ||
<input type="text" v-model="username" required> <!-- Change type to text and v-model to username --> | ||
</div> | ||
<div> | ||
<label>Password:</label> | ||
<input type="password" v-model="password" required> | ||
</div> | ||
<button type="submit">Login</button> | ||
</form> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { ref } from 'vue'; | ||
import { useAuthStore } from '@/store/auth'; | ||
|
||
export default { | ||
name: 'Login', | ||
setup() { | ||
const authStore = useAuthStore(); | ||
const username = ref(''); | ||
const password = ref(''); | ||
|
||
const login = async () => { | ||
try { | ||
await authStore.login(username.value, password.value); | ||
// Redirect to home page or wherever needed after successful login | ||
// Example: router.push('/home'); | ||
} catch (error) { | ||
console.error(error); | ||
// Handle login error | ||
} | ||
}; | ||
|
||
return { | ||
username, | ||
password, | ||
login, | ||
}; | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
/* Add your styles for Login */ | ||
</style> | ||
|
||
<div class="container"> | ||
<h1>Login</h1> | ||
<form @submit.prevent="login"> | ||
<div> | ||
<label>Username:</label> | ||
<input type="text" v-model="username" required> | ||
</div> | ||
<div> | ||
<label>Password:</label> | ||
<input type="password" v-model="password" required> | ||
</div> | ||
<button type="submit">Login</button> | ||
</form> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { ref } from 'vue'; | ||
import { useAuthStore } from '@/store/auth'; | ||
import { useRouter } from 'vue-router'; | ||
|
||
export default { | ||
name: 'Login', | ||
setup() { | ||
const authStore = useAuthStore(); | ||
const router = useRouter(); | ||
const username = ref(''); | ||
const password = ref(''); | ||
|
||
const login = async () => { | ||
try { | ||
await authStore.login(username.value, password.value); | ||
// Redirect to home page after successful login | ||
router.push('/home'); | ||
} catch (error) { | ||
console.error(error); | ||
// Handle login error | ||
} | ||
}; | ||
|
||
return { | ||
username, | ||
password, | ||
login, | ||
}; | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
/* Add your styles for Login */ | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,38 @@ | ||
<!-- Navbar.vue --> | ||
|
||
<template> | ||
<nav> | ||
<div class="container"> | ||
<div class="brand"> | ||
My App | ||
</div> | ||
<div v-if="isLoggedIn" class="user-info"> | ||
Logged in as {{ userEmail }} | ||
</div> | ||
<nav> | ||
<div class="container"> | ||
<div class="brand"> | ||
My App | ||
</div> | ||
</nav> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, computed } from 'vue'; | ||
import { useAuthStore } from '@/store/auth'; | ||
|
||
export default defineComponent({ | ||
name: 'Navbar', | ||
setup() { | ||
const authStore = useAuthStore(); | ||
|
||
const isLoggedIn = computed(() => authStore.isLoggedIn); | ||
const userEmail = computed(() => authStore.userEmail); | ||
|
||
return { | ||
isLoggedIn, | ||
userEmail, | ||
}; | ||
} | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
/* Add your scoped styles for Navbar */ | ||
</style> | ||
|
||
<div v-if="isLoggedIn" class="user-info"> | ||
Logged in as {{ username }} | ||
</div> | ||
</div> | ||
</nav> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, computed } from 'vue'; | ||
import { useAuthStore } from '@/store/auth'; | ||
|
||
export default defineComponent({ | ||
name: 'Navbar', | ||
setup() { | ||
const authStore = useAuthStore(); | ||
|
||
const isLoggedIn = computed(() => authStore.isLoggedIn); | ||
const username = computed(() => authStore.username); | ||
|
||
return { | ||
isLoggedIn, | ||
username, | ||
}; | ||
} | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
/* Add your scoped styles for Navbar */ | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
<!-- views/HomePage.vue --> | ||
|
||
<template> | ||
<div class="container"> | ||
<h1>Home Page</h1> | ||
<p>Welcome to the Home Page</p> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue'; | ||
|
||
export default defineComponent({ | ||
name: 'HomePage', | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
/* Add scoped styles for HomePage */ | ||
</style> | ||
|
||
<div class="container"> | ||
<h1>Home Page</h1> | ||
<p>Welcome to the Home Page, {{ username }}</p> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, computed } from 'vue'; | ||
import { useAuthStore } from '@/store/auth'; | ||
|
||
export default defineComponent({ | ||
name: 'HomePage', | ||
setup() { | ||
const authStore = useAuthStore(); | ||
const username = computed(() => authStore.username); | ||
|
||
return { | ||
username, | ||
}; | ||
} | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
/* Add your styles for HomePage */ | ||
</style> |