Skip to content

Commit d0344d3

Browse files
committed
[auth][xs]: bug fixes on user account delete.
- 'deleteIdentity' method is moved to 'AdminApi' now. - if deleting an identity fails, we should not display 500 error page but just a flash message.
1 parent bb0b0fe commit d0344d3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

routes/auth/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
const request = require('request')
2-
const { Configuration, PublicApi } = require('@oryd/kratos-client')
2+
const { Configuration, PublicApi, AdminApi } = require('@oryd/kratos-client')
33
const config = require('../../config')
44
const { authHandler } = require('./authHandler')
55
const { dashboard } = require('./dashboard')
66
const { errorHandler } = require('./errorHandler')
77
const logger = require('../../utils/logger')
88
const proxy = require('express-http-proxy')
99

10-
const kratos = new PublicApi(new Configuration({basePath: config.get('kratos').public}))
10+
const kratos = new PublicApi(new Configuration({ basePath: config.get('kratos').public }))
11+
const adminApi = new AdminApi(new Configuration({ basePath: config.get('kratos').admin }))
1112

1213
const protect = (req, res, next) => {
1314
// When using ORY Oathkeeper, the redirection is done by ORY Oathkeeper.
@@ -68,13 +69,17 @@ module.exports = function(app) {
6869
res.redirect('/.ory/kratos/public/self-service/browser/flows/logout')
6970
})
7071
app.post('/auth/delete', protect, (req, res, next) => {
71-
kratos.deleteIdentity(res.locals.userId)
72+
adminApi.deleteIdentity(res.locals.userId)
7273
.then(response => {
7374
res.redirect('/auth/registration')
7475
})
7576
.catch(err => {
7677
logger.error(err)
77-
next(err)
78+
req.flash(
79+
'info',
80+
'We could not delete your account this time. Please, try again later. If the issue persists, please contact the site administration.'
81+
)
82+
res.redirect('/settings')
7883
})
7984
})
8085
app.get('/error', errorHandler)

0 commit comments

Comments
 (0)