update: change auth mechanism to be unified for all sites

This commit is contained in:
MTG2000
2022-06-15 17:58:12 +03:00
parent f5eee8691e
commit cc566df768
4 changed files with 23 additions and 24 deletions

View File

@@ -57,7 +57,7 @@ function removeExpiredHashes() {
}
async function generateAuthUrl() {
const hostname = CONSTS.LNURL_AUTH_HOST;
const hostname = 'https://auth.bolt.fun/.netlify/functions/login';
const secret = await generateK1();
const hash = createHash(secret);
await addHash(hash)

View File

@@ -13,9 +13,8 @@ const { JWT_SECRET } = require('../../utils/consts');
const getLoginUrl = async (req, res) => {
try {
const data = await LnurlAuthService.generateAuthUrl();
const maxAge = 1000 * 60 * 3; //2 mins
const jwt = await new jose.SignJWT({ hash: data.secretHash })
const session_token = await new jose.SignJWT({ hash: data.secretHash })
.setProtectedHeader({ alg: 'HS256' })
.setIssuedAt()
.setExpirationTime('5min')
@@ -23,13 +22,7 @@ const getLoginUrl = async (req, res) => {
return res
.status(200)
.cookie('login_session', jwt, {
maxAge,
secure: true,
httpOnly: true,
sameSite: "none",
})
.json(data);
.json({ ...data, session_token });
} catch (error) {
console.log(error);
res.status(500).send("Unexpected error happened, please try again")

View File

@@ -9,7 +9,7 @@ const lnurlAuthService = require('../../auth/services/lnurlAuth.service');
const isLoggedInHandler = async (req, res) => {
try {
const login_session = req.cookies?.login_session;
const login_session = req.headers.session_token;
if (login_session) {
const { payload } = await jose.jwtVerify(login_session, Buffer.from(JWT_SECRET), {
algorithms: ['HS256'],
@@ -61,7 +61,7 @@ if (process.env.LOCAL) {
}
else {
const router = express.Router();
router.get('/is-logged-in', isLoggedInHandler)
router.get('/is-logged-in', (isLoggedInHandler))
app = createExpressApp(router)
}