ログイン画面推移できるように

This commit is contained in:
rca 2024-07-19 01:57:27 +09:00
parent dfcdccb2d7
commit 268d7b1847
3 changed files with 19 additions and 20 deletions

View File

@ -18,15 +18,13 @@
<script setup lang="ts">
import useStore from 'src/store';
import router from 'src/router';
const store = useStore();
if (store.state.account.isLoggedIn) {
// debug, show alert
alert('User is logged in');
} else {
// debug, show alert
alert('User is not logged in');
if (!store.state.account.isLoggedIn) {
// to /login
router.push('/login');
}
import { sendPing } from 'src/api/apiService';

View File

@ -20,6 +20,7 @@
import { ref, computed } from 'vue';
import useStore from 'src/store';
import { loginWithCode } from 'src/api/apiService';
import router from 'src/router';
const loginCode = ref('');
@ -32,6 +33,7 @@ const login = () => {
loginWithCode(loginCode.value).then((accessToken) => {
store.commit('account/setToken', accessToken);
store.commit('account/setLoggedIn', true);
router.push('/');
}).catch((error) => {
alert('ログインエラー: ' + error);
});

View File

@ -4,6 +4,7 @@ import {
createRouter,
createWebHashHistory,
createWebHistory,
Router,
} from 'vue-router';
import { RootStateInterface } from '../store';
@ -18,20 +19,18 @@ import routes from './routes';
* with the Router instance.
*/
export default route<RootStateInterface>(function (/* { store, ssrContext } */) {
const createHistory = process.env.SERVER
? createMemoryHistory
: (process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory);
const createHistory = process.env.SERVER
? createMemoryHistory
: (process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory);
const Router = createRouter({
scrollBehavior: () => ({ left: 0, top: 0 }),
routes,
// Leave this as is and make changes in quasar.conf.js instead!
// quasar.conf.js -> build -> vueRouterMode
// quasar.conf.js -> build -> publicPath
history: createHistory(process.env.VUE_ROUTER_BASE),
});
return Router;
const router: Router = createRouter({
scrollBehavior: () => ({ left: 0, top: 0 }),
routes,
// Leave this as is and make changes in quasar.conf.js instead!
// quasar.conf.js -> build -> vueRouterMode
// quasar.conf.js -> build -> publicPath
history: createHistory(process.env.VUE_ROUTER_BASE),
});
export default router;