mirror of
https://github.com/aljazceru/landscape-template.git
synced 2026-01-23 16:24:21 +01:00
update: change auth mechanism to be unified for all sites
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user