File tree Expand file tree Collapse file tree 3 files changed +23
-8
lines changed Expand file tree Collapse file tree 3 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 39
39
<span
40
40
class =" text-white text-lg font-bold flex items-center justify-center h-full w-full"
41
41
>
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
+ }}
43
47
</span >
44
48
</div >
45
49
</label >
Original file line number Diff line number Diff line change @@ -86,10 +86,23 @@ export const useAuthStore = defineStore("auth", {
86
86
if ( token ) {
87
87
this . token = token ;
88
88
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
+ }
91
104
92
- // For simplicity, we'll just set a basic user object
105
+ // Fallback to default user if token parsing fails
93
106
this . user = { username : "User" } ;
94
107
}
95
108
} ,
Original file line number Diff line number Diff line change @@ -3,9 +3,7 @@ import vue from "@vitejs/plugin-vue";
3
3
import { fileURLToPath , URL } from "node:url" ;
4
4
5
5
// 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" ;
9
7
10
8
export default defineConfig ( {
11
9
plugins : [ vue ( ) ] ,
@@ -18,7 +16,7 @@ export default defineConfig({
18
16
server : {
19
17
proxy : {
20
18
"/api" : {
21
- target : API_SERVER ,
19
+ target : API_URL ,
22
20
changeOrigin : true ,
23
21
ws : true , // Enable WebSocket proxy
24
22
} ,
You can’t perform that action at this time.
0 commit comments