[user] reload $user when opening /account (some old avatars lagging behind in the token on other locales)

This commit is contained in:
Andrea 2022-05-07 09:36:48 -05:00
parent db3edbcf1b
commit 001999a069
2 changed files with 25 additions and 0 deletions

View File

@ -226,6 +226,10 @@
async mounted() {
this.profiles = (await this.$axios.$get(`/profile/get/${this.$user().username}`)).profiles;
this.socialConnections = await this.$axios.$get(`/user/social-connections`);
const user = await this.$axios.$get(`/user/current`);
if (user) {
this.$store.commit('setToken', user.token);
}
if (process.client) {
const redirectTo = window.sessionStorage.getItem('after-login');

View File

@ -250,6 +250,27 @@ const router = Router();
router.use(handleErrorAsync(reloadUser));
router.get('/user/current', handleErrorAsync(async (req, res) => {
if (!req.user) {
res.clearCookie('token');
return res.json(null);
}
let dbUser = await req.db.get(SQL`SELECT * FROM users WHERE id = ${req.user.id}`);
if (!dbUser) {
res.clearCookie('token');
return res.json(null);
}
const token = await issueAuthentication(req.db, dbUser, false);
res.cookie('token', token, cookieSettings);
req.rawUser = jwt.validate(token);
req.user = req.rawUser;
return res.json({...req.user, token});
}));
router.post('/user/init', handleErrorAsync(async (req, res) => {
if (req.body.usernameOrEmail && isSpam(req.body.usernameOrEmail || '')) {
req.socket.end();