Skip to content

Commit

Permalink
feat(auth): adjust guest username helper to use @nextcloud/auth
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
  • Loading branch information
elzody committed Aug 14, 2024
1 parent 406d4a3 commit 4739d9b
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions src/helpers/guestName.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,17 @@ import {
} from '@nextcloud/auth'
import getLoggedInUser from '../helpers/getLoggedInUser.js'

const cookieAlreadySet = (cookieName) => {
return document.cookie
.split(';')
.some(cookie => {
return cookie.trim().startsWith(`${cookieName}=`)
})
}

const setGuestNameCookie = (username) => {
if (username !== '') {
document.cookie = 'guestUser=' + encodeURIComponent(username) + '; path=/'
}
}

const shouldAskForGuestName = () => {
/**
* Determines if the user should be asked to enter a guest name
*
* @param {string} mimetype - Mimetype of the file
* @param {boolean} canWrite - If write access is granted
*/
export function shouldAskForGuestName(mimetype, canWrite) {
const noLoggedInUser = !getLoggedInUser()
const noGuest = !getGuestNickname()
const noCurrentUser = !getCurrentUser() || getCurrentUser()?.uid === ''
const isReadOnlyPDF = mimetype === 'application/pdf' && !canWrite

return noLoggedInUser && noGuestCookie && noCurrentUser
}

export {
setGuestNameCookie,
shouldAskForGuestName,
return noLoggedInUser && noGuest && noCurrentUser && !isReadOnlyPDF
}

0 comments on commit 4739d9b

Please sign in to comment.