-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: get already logged in user via initial state
Signed-off-by: Elizabeth Danzberger <[email protected]>
- Loading branch information
Showing
5 changed files
with
53 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
import axios from '@nextcloud/axios' | ||
import { generateUrl } from '@nextcloud/router' | ||
|
||
/** | ||
* Gets the current user's display name if logged in. | ||
* @copyright Copyright (c) 2024 Elizabeth Danzberger <[email protected]> | ||
* | ||
* @author Elizabeth Danzberger <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @return null | string | ||
*/ | ||
async function getLoggedInUser() { | ||
try { | ||
const res = await axios.get(generateUrl('apps/files/public')) | ||
|
||
if (res.status !== 200) { | ||
return null | ||
} | ||
import { loadState } from '@nextcloud/initial-state' | ||
|
||
const el = document.createElement('html') | ||
el.innerHTML = res.data | ||
|
||
const userAttributes = el.querySelector('head[data-user]').attributes | ||
|
||
return userAttributes.getNamedItem('data-user-displayname').textContent | ||
} catch (err) { | ||
if (err.status === 401) { | ||
console.error(err.statusText) | ||
} | ||
} | ||
/** | ||
* Gets the current user's display name if logged in. | ||
* | ||
* @return boolean | string | ||
*/ | ||
function getLoggedInUser() { | ||
return loadState('richdocuments', 'loggedInUser') | ||
} | ||
|
||
export default getLoggedInUser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters