This commit is contained in:
MTG2000
2022-06-09 13:37:38 +03:00
parent f9b622ae25
commit e7b341fc2d
2 changed files with 13 additions and 9 deletions

View File

@@ -2,17 +2,20 @@ const { ApolloServer } = require("apollo-server-lambda");
const schema = require('./schema')
const cookie = require('cookie')
const jose = require('jose');
const { createExpressApp } = require("../../modules");
const { JWT_SECRET } = require("../../utils/consts");
const extractKey = async (cookieHeader) => {
const cookies = cookie.parse(cookieHeader ?? '');
const token = cookies.Authorization;
if (token) {
const { payload } = await jose.jwtVerify(token, Buffer.from(JWT_SECRET), {
algorithms: ['HS256'],
})
return payload.pubKey
try {
const { payload } = await jose.jwtVerify(token, Buffer.from(JWT_SECRET), {
algorithms: ['HS256'],
})
return payload.pubKey
} catch (error) {
return null
}
}
return null;
}

View File

@@ -19,20 +19,21 @@ const isLoggedInHandler = async (req, res) => {
algorithms: ['HS256'],
});
const hash = payload.hash;
console.log(hash);
const token = await getAuthTokenByHash(hash);
console.log(token);
lnurlService.removeHash(hash).catch();
lnurlService.removeExpiredHashes().catch();
res
.status(200)
.cookie('Authorization', token, {
maxAge: 3600000 * 24 * 30,
.clearCookie('login_session', {
secure: true,
httpOnly: true,
})
.clearCookie('login_session', {
.cookie('Authorization', token, {
maxAge: 3600000 * 24 * 30,
secure: true,
httpOnly: true,
})