Skip to content

Commit

Permalink
feat: updated
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullah4tech committed Aug 13, 2024
1 parent b37fd38 commit 4c254bd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/views/Auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import axios from 'axios';
import { useToast } from '@/components/ui/toast/use-toast'
import { Toaster, ToastAction } from '@/components/ui/toast'
import useAuthStore from '@/stores/authSore';
import { Loader2 } from 'lucide-vue-next';
const loading = ref(false)
const { toast } = useToast();
Expand Down Expand Up @@ -66,6 +68,7 @@ const validateForm = () => {
const onSubmit = async () => {
if (!validateForm()) return;
loading.value = true
axios.post('https://backend-aurh-production.up.railway.app/api/login', {
email: form.value.email.trim(),
password: form.value.password.trim()
Expand All @@ -77,9 +80,11 @@ const onSubmit = async () => {
})
.then((res) => {
authStore.setAuthentication(res.data.token)
loading.value = false
router.push('/')
})
.catch((err) => {
loading.value = false
toast({
variant: 'destructive',
title: 'Uh oh! Something went wrong.',
Expand Down Expand Up @@ -122,6 +127,7 @@ const toggleShowPassword = () => {
:type="showPassword ? 'text' : 'password'"
placeholder="********"
v-model="form.password"
@keydown.enter="onSubmit"
/>
<Button
type="button"
Expand All @@ -134,12 +140,20 @@ const toggleShowPassword = () => {
</div>
<p v-if="errors.password" class="text-red-500 text-sm">{{ errors.password }}</p>
</div>
<RouterLink to="/auth/reset" class="text-right">
<a to="/auth/reset" class="text-right">
<Button variant="link" class="ml-auto md:text-sm">Forgot your password?</Button>
</RouterLink>
</a>
</CardContent>
<CardFooter class="flex-col space-y-2">
<Button class="w-full" type="submit">Login</Button>
<Button class="w-full" type="submit">
<div v-if="loading" class="flex">
<Loader2 class="w-4 h-4 mr-2 animate-spin" />
Please wait
</div>
<div v-else>
Login
</div>
</Button>
<p class="text-sm">
Don't have an account?
<RouterLink
Expand Down
18 changes: 17 additions & 1 deletion src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Button } from '@/components/ui/button';
import useAuthStore from '@/stores/authSore';
import { onMounted, ref } from 'vue';
import { Loader2 } from 'lucide-vue-next';
const authStore = useAuthStore();
Expand All @@ -13,11 +14,18 @@ interface User {
// Initialize `user` as a ref with an initial empty object
const user = ref<User | null>(null);
const loading = ref(false)
const checkAuth = async () => {
// Assuming `authStore.user_info` is of type `User`
user.value = authStore.user_info || null;
};
const signOut = () => {
loading.value = true
authStore.logOut()
}
onMounted(() => {
checkAuth();
});
Expand All @@ -30,7 +38,15 @@ onMounted(() => {
Email: {{ user.email }}
</div>
<div>
<Button @click="authStore.logOut()">Logout</Button>
<Button @click="signOut">
<div v-if="loading" class="flex">
<Loader2 class="w-4 h-4 mr-2 animate-spin" />
Please wait
</div>
<div v-else>
Logout
</div>
</Button>
</div>
</div>
</template>

0 comments on commit 4c254bd

Please sign in to comment.