Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Github lost our code :)
  • Loading branch information
NaysKutzu committed Feb 9, 2025
1 parent e5d92fa commit ddd469c
Show file tree
Hide file tree
Showing 23 changed files with 262 additions and 156 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"js-cookie": "^3.0.5",
"jspdf": "^2.5.2",
"lucide-vue-next": "^0.468.0",
"pinia": "^2.3.1",
"qrcode": "^1.5.4",
"three": "^0.172.0",
"vue": "^3.5.12",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/admin/LayoutDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ import {
} from 'lucide-vue-next';
import Session from '@/mythicalclient/Session';
import StorageMonitor from '@/mythicalclient/StorageMonitor';
import Settings from '@/mythicalclient/Settings';

import { useSettingsStore } from '@/stores/settings';
const Settings = useSettingsStore();
const router = useRouter();

new StorageMonitor();
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/client/Auth/FormCard.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { HelpCircleIcon } from 'lucide-vue-next';
import Settings from '@/mythicalclient/Settings';
import { useI18n } from 'vue-i18n';
import { useSettingsStore } from '@/stores/settings';
const Settings = useSettingsStore();
const { t } = useI18n();
defineProps({
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/client/layout/TopNavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ import {
Menu as MenuIcon,
X as XIcon,
} from 'lucide-vue-next';
import Settings from '@/mythicalclient/Settings';
import { useSettingsStore } from '@/stores/settings';
const Settings = useSettingsStore();
import { useI18n } from 'vue-i18n';
import Session from '@/mythicalclient/Session';
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import './assets/main.css';

import { createApp } from 'vue';
import { createPinia } from 'pinia';
import App from './App.vue';
import router from './router';
import VueSweetalert2 from 'vue-sweetalert2';
import { createI18n } from 'vue-i18n';
import EN from '@/locale/en.yml';
import Settings from '@/mythicalclient/Settings';
import './assets/sweetalert2.css';
const app = createApp(App);
const pinia = createPinia();

app.use(pinia);
app.use(router);
app.use(VueSweetalert2);

Expand All @@ -21,6 +23,5 @@ const i18n = createI18n({
});
app.use(i18n);

Settings.initializeSettings();

app.mount('#app');
4 changes: 2 additions & 2 deletions frontend/src/mythicalclient/MythicalClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Settings from '@/mythicalclient/Settings';

import { useSettingsStore } from '@/stores/settings';
interface MythicalClientOptions {
timeout?: number;
theme?: 'dark' | 'light';
Expand Down Expand Up @@ -318,6 +317,7 @@ export class MythicalClient {
console.log(`%c${randomMessages[Math.floor(Math.random() * randomMessages.length)]}`, styles.success);

// Version Info
const Settings = useSettingsStore();
console.log('%c📦 Version: ' + Settings.getSetting('version'));

// Credits
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/mythicalclient/MythicalDOM.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Settings from './Settings';
import { useSettingsStore } from '@/stores/settings';
import { useI18n } from 'vue-i18n';
export class MythicalDOM {
/**
* Sets the page title
* @param title The title to set for the page
*/
public static setPageTitle(title: string): void {
const Settings = useSettingsStore();
document.title = Settings.getSetting('app_name') + ' - ' + title;
}

Expand Down
3 changes: 0 additions & 3 deletions frontend/src/mythicalclient/Session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import router from '@/router';
import Swal from 'sweetalert2';
import Settings from '@/mythicalclient/Settings';
import { useI18n } from 'vue-i18n';

interface SessionResponse {
Expand Down Expand Up @@ -77,8 +76,6 @@ class Session {
*/
private static async handleSessionError(data: SessionResponse): Promise<void> {
const { t } = useI18n();
await Settings.initializeSettings();

// Remove the user_token cookie
document.cookie = 'user_token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';

Expand Down
130 changes: 0 additions & 130 deletions frontend/src/mythicalclient/Settings.ts

This file was deleted.

52 changes: 52 additions & 0 deletions frontend/src/stores/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
import router from '@/router';

interface SessionResponse {
success: boolean;
error_code?: string;
user_info: Record<string, unknown>;
billing: Record<string, unknown>;
}

export const useSessionStore = defineStore('session', () => {
const sessionInfo = ref<Record<string, unknown>>({});
const isValid = ref(false);

async function startSession() {
try {
const response = await fetch('/api/user/session');
const data: SessionResponse = await response.json();

if (data.success) {
sessionInfo.value = { ...data.user_info, ...data.billing };
isValid.value = true;
} else {
isValid.value = false;
if (data.error_code === 'SESSION_EXPIRED') {
router.push('/auth/login');
}
}
} catch (error) {
console.error('Session error:', error);
isValid.value = false;
router.push('/auth/login');
}
}

function getInfo(key: string): string {
return (sessionInfo.value[key] as string) || '';
}

function isSessionValid(): boolean {
return isValid.value;
}

return {
sessionInfo,
isValid,
startSession,
getInfo,
isSessionValid,
};
});
Loading

0 comments on commit ddd469c

Please sign in to comment.