Skip to content

Commit 3e7104b

Browse files
committed
Handle errors for user not logged in
1 parent aded903 commit 3e7104b

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

lib/requests/consent-request.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,18 @@ class ConsentRequest extends AuthRequest {
6565
*/
6666
static async get (req, res) {
6767
const request = ConsentRequest.fromParams(req, res)
68+
6869
const appOrigin = request.getAppOrigin()
6970
// Check if is already registered or is data browser
70-
if (
71-
appOrigin === req.app.locals.ldp.serverUri ||
72-
await request.isAppRegistered(req.app.locals.ldp, appOrigin, request.authQueryParams.web_id)
73-
) {
74-
request.redirectPostConsent()
75-
} else {
76-
request.renderForm(null, req)
71+
if (request.isUserLoggedIn()) {
72+
if (
73+
appOrigin === req.app.locals.ldp.serverUri ||
74+
await request.isAppRegistered(req.app.locals.ldp, appOrigin, request.session.subject._id)
75+
) {
76+
request.redirectPostConsent()
77+
} else {
78+
request.renderForm(null, req)
79+
}
7780
}
7881
}
7982

@@ -96,23 +99,27 @@ class ConsentRequest extends AuthRequest {
9699

97100
let request = ConsentRequest.fromParams(req, res)
98101

99-
// Ensure the user arrived here by logging in
100-
if (!request.session.subject && request.session.subject._id) {
101-
const error = new Error('User not logged in')
102-
error.statusCode = 401
103-
throw error
104-
}
102+
if (request.isUserLoggedIn()) {
103+
const appOrigin = request.getAppOrigin()
104+
debug('Providing consent for app sharing')
105105

106-
const appOrigin = request.getAppOrigin()
107-
debug('Providing consent for app sharing')
106+
if (consented) {
107+
await request.registerApp(req.app.locals.ldp, appOrigin, accessModes, request.session.subject._id)
108+
}
108109

109-
if (consented) {
110-
await request.registerApp(req.app.locals.ldp, appOrigin, accessModes, request.session.subject._id)
110+
// Redirect once that's all done
111+
request.redirectPostConsent()
111112
}
113+
}
112114

113-
console.log('oh no didnt update')
114-
// Redirect once that's all done
115-
request.redirectPostConsent()
115+
isUserLoggedIn () {
116+
// Ensure the user arrived here by logging in
117+
if (!this.session.subject || !this.session.subject._id) {
118+
this.response.status(401)
119+
this.response.send('User not logged in 2')
120+
return false
121+
}
122+
return true
116123
}
117124

118125
getAppOrigin () {
@@ -136,7 +143,6 @@ class ConsentRequest extends AuthRequest {
136143

137144
async saveProfileGraph (ldp, store, webId) {
138145
const text = $rdf.serialize(undefined, store, webId, 'text/turtle')
139-
console.log(text)
140146
await ldp.put(webId, intoStream(text), 'text/turtle')
141147
}
142148

@@ -163,7 +169,6 @@ class ConsentRequest extends AuthRequest {
163169
accessModes.forEach(mode => {
164170
store.add(application, ACL('mode'), ACL(mode))
165171
})
166-
console.log(store)
167172
await this.saveProfileGraph(ldp, store, webId)
168173
}
169174

0 commit comments

Comments
 (0)