Skip to content

Commit

Permalink
fix: detect login and update state
Browse files Browse the repository at this point in the history
  • Loading branch information
darlanalves authored May 17, 2024
1 parent d70c15d commit 75a372f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion components/Console.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<PageLayout :title="'Available Commands'">
<PageLayout :title="'Console'">
<form class="flex items-center" @submit.prevent="onRun()">
<input
class="font-mono text-sm flex-grow w-full p-2 block rounded-l-md border border-gray-300 shadow-sm"
Expand Down
2 changes: 1 addition & 1 deletion components/apps/AppRoutes.vue → components/Routes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useCommands } from '../../composables/useCommands';
import { useCommands } from '../composables/useCommands';
const { run } = useCommands();
const routeList = ref([]);
Expand Down
18 changes: 11 additions & 7 deletions composables/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { ref, onMounted } from 'vue';

const isLoggedIn = ref(false);
const profile = ref(null);
const auth: any = ref(null);

export function useAuth() {
const profile = ref(null);
function setProfile(p) {
profile.value = p;
isLoggedIn.value = !!p;
}

export function useAuth() {
async function refresh() {
try {
profile.value = await auth.value.getProfile();
isLoggedIn.value = !!profile.value;
setProfile(await auth.value.getProfile());
} catch {
profile.value = null;
isLoggedIn.value = false;
setProfile(null);
}
}

Expand Down Expand Up @@ -45,5 +47,7 @@ export function useAuth() {
}

export async function load(env) {
auth.value = await import(String(new URL('/auth.js', env.AUTH_HOST)));
const lib = await import(String(new URL('/auth.js', env.AUTH_HOST)));
auth.value = lib;
lib.events.addEventListener('signin', (e: CustomEvent) => setProfile(e.detail));
}
2 changes: 1 addition & 1 deletion composables/useRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Console from '../components/Console.vue';
import Settings from '../components/Settings.vue';
import AppList from '../components/apps/AppList.vue';
import AppDetails from '../components/apps/AppDetails.vue';
import AppRoutes from '../components/apps/AppRoutes.vue';
import AppRoutes from '../components/Routes.vue';

const topPages = [
{
Expand Down
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApp } from 'vue';
import App from './components/App.vue';
import App from './App.vue';
import AppError from './components/AppError.vue';
import { router } from './composables/useRouter.js';
import { setEnv } from './composables/useEnv.js';
Expand Down

0 comments on commit 75a372f

Please sign in to comment.