#85 universal login across locales - attempt
This commit is contained in:
parent
a034337f12
commit
97870e2b5c
|
@ -121,6 +121,14 @@
|
||||||
<T>user.deleteAccount</T>
|
<T>user.deleteAccount</T>
|
||||||
</a>
|
</a>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<iframe v-for="domain in universalDomains"
|
||||||
|
:src="`${domain}/api/user/init-universal/${$cookies.get('token')}`"
|
||||||
|
style="width: 1px; height: 1px; opacity: .01"
|
||||||
|
>
|
||||||
|
</iframe>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -152,6 +160,8 @@
|
||||||
gravatar,
|
gravatar,
|
||||||
|
|
||||||
captchaToken: null,
|
captchaToken: null,
|
||||||
|
|
||||||
|
universalDomains: process.env.ALL_LOCALES_URLS.split(',').filter(x => x !== process.env.BASE_URL),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { loadSuml } from './server/loader';
|
import { loadSuml } from './server/loader';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import {buildDict, buildLocaleList} from "./src/helpers";
|
import {buildDict, buildList, buildLocaleList} from "./src/helpers";
|
||||||
|
|
||||||
const config = loadSuml('config');
|
const config = loadSuml('config');
|
||||||
const translations = loadSuml('translations');
|
const translations = loadSuml('translations');
|
||||||
|
@ -14,6 +14,18 @@ const colour = '#C71585';
|
||||||
|
|
||||||
process.env.LOCALE = locale;
|
process.env.LOCALE = locale;
|
||||||
|
|
||||||
|
const allVersionsUrls = buildList(function*() {
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
yield 'http://pronouns.test:3000';
|
||||||
|
yield 'http://localhost:3000';
|
||||||
|
} else {
|
||||||
|
for (let loc in locales) {
|
||||||
|
yield locales[loc].url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
process.env.ALL_LOCALES_URLS = allVersionsUrls.join(',');
|
||||||
|
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
const buildFlags = () => {
|
const buildFlags = () => {
|
||||||
|
@ -154,6 +166,7 @@ export default {
|
||||||
BUCKET: `https://${process.env.AWS_S3_BUCKET}.s3-${process.env.AWS_REGION}.amazonaws.com`,
|
BUCKET: `https://${process.env.AWS_S3_BUCKET}.s3-${process.env.AWS_REGION}.amazonaws.com`,
|
||||||
STATS_FILE: process.env.STATS_FILE,
|
STATS_FILE: process.env.STATS_FILE,
|
||||||
HCAPTCHA_SITEKEY: process.env.HCAPTCHA_SITEKEY,
|
HCAPTCHA_SITEKEY: process.env.HCAPTCHA_SITEKEY,
|
||||||
|
ALL_LOCALES_URLS: process.env.ALL_LOCALES_URLS,
|
||||||
},
|
},
|
||||||
serverMiddleware: ['~/server/no-ssr.js', '~/server/index.js'],
|
serverMiddleware: ['~/server/no-ssr.js', '~/server/index.js'],
|
||||||
axios: {
|
axios: {
|
||||||
|
|
|
@ -467,4 +467,13 @@ router.post('/user/set-avatar', handleErrorAsync(async (req, res) => {
|
||||||
return res.json({token: await issueAuthentication(req.db, req.user)});
|
return res.json({token: await issueAuthentication(req.db, req.user)});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
router.get('/user/init-universal/:token', handleErrorAsync(async (req, res) => {
|
||||||
|
if (!req.user) {
|
||||||
|
return res.json('Already logged in');
|
||||||
|
}
|
||||||
|
|
||||||
|
res.cookie('token', req.params.token, cookieSettings);
|
||||||
|
return res.json('Token saved');
|
||||||
|
}));
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Jwt {
|
||||||
return jwt.sign(payload, this.privateKey, {
|
return jwt.sign(payload, this.privateKey, {
|
||||||
expiresIn,
|
expiresIn,
|
||||||
algorithm: 'RS256',
|
algorithm: 'RS256',
|
||||||
audience: process.env.BASE_URL,
|
audience: process.env.ALL_LOCALES_URLS.split(','),
|
||||||
issuer: process.env.BASE_URL,
|
issuer: process.env.BASE_URL,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ class Jwt {
|
||||||
try {
|
try {
|
||||||
return jwt.verify(token, this.publicKey, {
|
return jwt.verify(token, this.publicKey, {
|
||||||
algorithm: 'RS256',
|
algorithm: 'RS256',
|
||||||
audience: process.env.BASE_URL,
|
audience: process.env.ALL_LOCALES_URLS.split(','),
|
||||||
issuer: process.env.BASE_URL,
|
issuer: process.env.ALL_LOCALES_URLS.split(','),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
|
@ -18,10 +18,11 @@ export const mutations = {
|
||||||
try {
|
try {
|
||||||
user = jwt.verify(token, process.env.PUBLIC_KEY, {
|
user = jwt.verify(token, process.env.PUBLIC_KEY, {
|
||||||
algorithm: 'RS256',
|
algorithm: 'RS256',
|
||||||
audience: process.env.BASE_URL,
|
audience: process.env.ALL_LOCALES_URLS.split(','),
|
||||||
issuer: process.env.BASE_URL,
|
issuer: process.env.ALL_LOCALES_URLS.split(','),
|
||||||
});
|
});
|
||||||
} catch {
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
user = null;
|
user = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue