mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #2630 from overleaf/sk-fix-token-login-redirect
Remember token page when redirect to login GitOrigin-RevId: 1c4d7b8ae034ef2d63cc680405c099405024f4d1
This commit is contained in:
parent
7cbb00f207
commit
2686f5e72a
3 changed files with 31 additions and 2 deletions
|
@ -158,7 +158,10 @@ async function checkAndGetProjectOrResponseAction(
|
|||
{ token, projectId },
|
||||
'[TokenAccess] deny anonymous read-and-write token access'
|
||||
)
|
||||
AuthenticationController.setRedirectInSession(req)
|
||||
AuthenticationController.setRedirectInSession(
|
||||
req,
|
||||
TokenAccessHandler.makeTokenUrl(token)
|
||||
)
|
||||
return [
|
||||
null,
|
||||
() => {
|
||||
|
|
|
@ -29,6 +29,25 @@ const TokenAccessHandler = {
|
|||
READ_ONLY_TOKEN_REGEX: new RegExp(`^${READ_ONLY_TOKEN_PATTERN}$`),
|
||||
READ_ONLY_URL_REGEX: new RegExp(`^/read/${READ_ONLY_TOKEN_PATTERN}$`),
|
||||
|
||||
makeReadAndWriteTokenUrl(token) {
|
||||
return `/${token}`
|
||||
},
|
||||
|
||||
makeReadOnlyTokenUrl(token) {
|
||||
return `/read/${token}`
|
||||
},
|
||||
|
||||
makeTokenUrl(token) {
|
||||
const tokenType = TokenAccessHandler.getTokenType(token)
|
||||
if (tokenType === TokenAccessHandler.TOKEN_TYPES.READ_AND_WRITE) {
|
||||
return TokenAccessHandler.makeReadAndWriteTokenUrl(token)
|
||||
} else if (tokenType === TokenAccessHandler.TOKEN_TYPES.READ_ONLY) {
|
||||
return TokenAccessHandler.makeReadOnlyTokenUrl(token)
|
||||
} else {
|
||||
throw new Error('invalid token type')
|
||||
}
|
||||
},
|
||||
|
||||
getTokenType(token) {
|
||||
if (!token) {
|
||||
return null
|
||||
|
|
|
@ -908,7 +908,14 @@ describe('TokenAccess', function() {
|
|||
expect(body).to.equal('Forbidden')
|
||||
},
|
||||
cb
|
||||
)
|
||||
),
|
||||
cb =>
|
||||
this.anon.login((err, response, body) => {
|
||||
expect(err).to.not.exist
|
||||
expect(response.statusCode).to.equal(200)
|
||||
expect(body.redir).to.equal(`/${this.tokens.readAndWrite}`)
|
||||
cb()
|
||||
})
|
||||
],
|
||||
done
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue