Skip to content

Commit 8f6886c

Browse files
committed
apps/dashboard: fix user icon display
1 parent 9f10ac2 commit 8f6886c

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

apps/dashboard/src/components/NavBar.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
<span
4040
class="text-white text-lg font-bold flex items-center justify-center h-full w-full"
4141
>
42-
{{ authStore.user?.username?.charAt(0).toUpperCase() || "U" }}
42+
{{
43+
authStore.user && authStore.user.username
44+
? authStore.user.username.charAt(0).toUpperCase()
45+
: "U"
46+
}}
4347
</span>
4448
</div>
4549
</label>

apps/dashboard/src/stores/authStore.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,23 @@ export const useAuthStore = defineStore("auth", {
8686
if (token) {
8787
this.token = token;
8888

89-
// You could also verify the token with the server here
90-
// or decode the JWT to get user info
89+
try {
90+
// Extract user info from JWT token
91+
// JWT tokens are in the format: header.payload.signature
92+
const payload = token.split(".")[1];
93+
if (payload) {
94+
// Decode the base64 payload
95+
const decodedPayload = JSON.parse(atob(payload));
96+
if (decodedPayload.username) {
97+
this.user = { username: decodedPayload.username };
98+
return;
99+
}
100+
}
101+
} catch (error) {
102+
console.error("Error decoding JWT token:", error);
103+
}
91104

92-
// For simplicity, we'll just set a basic user object
105+
// Fallback to default user if token parsing fails
93106
this.user = { username: "User" };
94107
}
95108
},

apps/dashboard/vite.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import vue from "@vitejs/plugin-vue";
33
import { fileURLToPath, URL } from "node:url";
44

55
// Get API server configuration from environment variables or use defaults
6-
const API_HOST = process.env.VITE_API_HOST || "localhost";
7-
const API_PORT = process.env.VITE_API_PORT || "9000";
8-
const API_SERVER = `http://${API_HOST}:${API_PORT}`;
6+
const API_URL = process.env.VITE_API_URL || "http://localhost:9000";
97

108
export default defineConfig({
119
plugins: [vue()],
@@ -18,7 +16,7 @@ export default defineConfig({
1816
server: {
1917
proxy: {
2018
"/api": {
21-
target: API_SERVER,
19+
target: API_URL,
2220
changeOrigin: true,
2321
ws: true, // Enable WebSocket proxy
2422
},

0 commit comments

Comments
 (0)