20 lines
499 B
TypeScript
20 lines
499 B
TypeScript
import axios from 'axios';
|
|
import { useRouter } from 'vue-router';
|
|
|
|
export async function checkAuth(router: any) {
|
|
try {
|
|
const response = await axios.get('/api/auth', {
|
|
withCredentials: true,
|
|
});
|
|
|
|
if (!response.data.success) {
|
|
router.push('/login');
|
|
}
|
|
|
|
return response.data.success;
|
|
} catch (error) {
|
|
console.log("Not authenticated, redirecting to /login");
|
|
router.push('/login');
|
|
return false;
|
|
}
|
|
}
|