From 88f2fc35cd8e863522596aabf7437f64bba25cd8 Mon Sep 17 00:00:00 2001
From: Deluan <deluan@navidrome.org>
Date: Fri, 30 Apr 2021 17:53:17 -0400
Subject: [PATCH] Fix regular users not able to edit their info before logging
 in again

---
 ui/src/dataProvider/httpClient.js | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ui/src/dataProvider/httpClient.js b/ui/src/dataProvider/httpClient.js
index 153c2cbd6..02e78ca83 100644
--- a/ui/src/dataProvider/httpClient.js
+++ b/ui/src/dataProvider/httpClient.js
@@ -1,6 +1,7 @@
 import { fetchUtils } from 'react-admin'
 import { baseUrl } from '../utils'
 import config from '../config'
+import jwtDecode from 'jwt-decode'
 
 const customAuthorizationHeader = 'X-ND-Authorization'
 
@@ -16,7 +17,9 @@ const httpClient = (url, options = {}) => {
   return fetchUtils.fetchJson(url, options).then((response) => {
     const token = response.headers.get(customAuthorizationHeader)
     if (token) {
+      const decoded = jwtDecode(token)
       localStorage.setItem('token', token)
+      localStorage.setItem('userId', decoded.uid)
       // Avoid going to create admin dialog after logout/login without a refresh
       config.firstTime = false
     }