Browse Source

Add temporary home page with logout button. Enable DB synchronization

master
David Ludwig 4 years ago
parent
commit
b204472c37
3 changed files with 27 additions and 9 deletions
  1. +14
    -6
      src/app/auth.ts
  2. +11
    -2
      src/app/views/Home.vue
  3. +2
    -1
      src/server/services/Database.ts

+ 14
- 6
src/app/auth.ts View File

@ -1,6 +1,11 @@
import jwtDecode from "jwt-decode";
interface IUser {
id: number,
name: string,
isAdmin: boolean
}
/**
* The active JWT
*/
@ -9,11 +14,7 @@ import jwtDecode from "jwt-decode";
/**
* The decoded user object
*/
let user: {
id: number,
name: string,
isAdmin: boolean
} | null;
let user: IUser | null;
/**
* Check if the user is an admin
@ -29,6 +30,13 @@ export function isAuthenticated() {
return Boolean(token);
}
/**
* Get the logged in user (assumes authentication has been checked)
*/
export function getUser() {
return <IUser>user;
}
/**
* Load the token from local storage
*/


+ 11
- 2
src/app/views/Home.vue View File

@ -1,11 +1,20 @@
<template>
<div></div>
<div class="mx-auto my-auto flex flex-col">
<span class="text-2xl">Welcome, {{ name }}</span>
<router-link :to="{name: 'Logout'}" class="bg-red-500 text-white p-3 rounded-lg shadow-md focus:outline-none hover:bg-red-600 text-center">Sign Out</router-link>
</div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import * as auth from "../auth";
export default defineComponent({
components: {}
components: {},
data() {
return {
name: auth.getUser().name.split(' ')[0]
}
}
});
</script>

+ 2
- 1
src/server/services/Database.ts View File

@ -33,7 +33,8 @@ export default class Database extends Service
username : process.env["DB_USER"],
password : password,
database : process.env["DB_DATABASE"],
synchronize: process.env["NODE_ENV"] != "production",
// synchronize: process.env["NODE_ENV"] != "production",
synchronize: true, // Seems stable enough for my liking
entities : Object.values(entities),
migrations : ["src/migrations/*.ts"]
});


Loading…
Cancel
Save