|
1 | 1 | const request = require('request') |
2 | | -const { Configuration, PublicApi } = require('@oryd/kratos-client') |
| 2 | +const { Configuration, PublicApi, AdminApi } = require('@oryd/kratos-client') |
3 | 3 | const config = require('../../config') |
4 | 4 | const { authHandler } = require('./authHandler') |
5 | 5 | const { dashboard } = require('./dashboard') |
6 | 6 | const { errorHandler } = require('./errorHandler') |
7 | 7 | const logger = require('../../utils/logger') |
8 | 8 | const proxy = require('express-http-proxy') |
9 | 9 |
|
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 })) |
11 | 12 |
|
12 | 13 | const protect = (req, res, next) => { |
13 | 14 | // When using ORY Oathkeeper, the redirection is done by ORY Oathkeeper. |
@@ -68,13 +69,17 @@ module.exports = function(app) { |
68 | 69 | res.redirect('/.ory/kratos/public/self-service/browser/flows/logout') |
69 | 70 | }) |
70 | 71 | app.post('/auth/delete', protect, (req, res, next) => { |
71 | | - kratos.deleteIdentity(res.locals.userId) |
| 72 | + adminApi.deleteIdentity(res.locals.userId) |
72 | 73 | .then(response => { |
73 | 74 | res.redirect('/auth/registration') |
74 | 75 | }) |
75 | 76 | .catch(err => { |
76 | 77 | 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') |
78 | 83 | }) |
79 | 84 | }) |
80 | 85 | app.get('/error', errorHandler) |
|
0 commit comments