-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't ask logged in user for guest username
Signed-off-by: Elizabeth Danzberger <[email protected]>
- Loading branch information
Showing
3 changed files
with
35 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import axios from '@nextcloud/axios' | ||
import { generateUrl } from '@nextcloud/router' | ||
|
||
/** | ||
* Gets the current user's display name if logged in. | ||
* | ||
* @return null | string | ||
*/ | ||
async function getLoggedInUser() { | ||
try { | ||
const res = await axios.get(generateUrl('apps/files/public')) | ||
|
||
if (res.status !== 200) { | ||
return null | ||
} | ||
|
||
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) | ||
} | ||
} | ||
} | ||
|
||
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
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