-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
78 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import jwt from "jsonwebtoken"; | ||
import { JWT_SECRET } from "../config"; | ||
import { prisma } from "../db"; | ||
|
||
|
||
|
||
|
||
export const authenticateToken = async (req, res, next) => { | ||
const token = req.headers.authorization?.split(" ")[1]; // Bearer token extraction | ||
if (!token) { | ||
return res.status(401).json({ ok: false, error: "No token provided" }); | ||
} | ||
|
||
try { | ||
const decoded = jwt.verify(token, JWT_SECRET); | ||
const user = await prisma.user.findUnique({ | ||
where: { email: decoded.email }, | ||
}); | ||
|
||
if (!user) { | ||
return res.status(400).json({ ok: false, error: "User not found" }); | ||
} | ||
|
||
// Attach user info to req object | ||
req.user = user; | ||
next(); // Proceed to the next middleware/route handler | ||
} catch (error) { | ||
return res.status(403).json({ ok: false, error: "Token is invalid or expired" }); | ||
} | ||
}; | ||
|
||
module.exports = { authenticateToken }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,18 +25,6 @@ export const initMatomo = async () => { | |
if (!userId) { | ||
userId = Matomo.makeid(); | ||
storage.set("@UserIdv2", userId); | ||
const response = await API.post({ | ||
path: "/user/signup", | ||
body: { | ||
matomoId: userId, | ||
email: "[email protected]", | ||
password: "password12@Abc", | ||
calledFrom: "initMatomo", | ||
}, | ||
}); | ||
if (response.ok) { | ||
storage.set("@Token", response.token); | ||
} | ||
} | ||
Sentry.setUser({ id: userId }); | ||
API.userId = userId; | ||
|
@@ -83,15 +71,6 @@ export const logEvent = async ({ category, action, name, value, dimension6 }) => | |
const canSend = await checkNetwork(); | ||
if (!canSend) throw new Error("no network"); | ||
Matomo.logEvent({ category, action, name, value, dimension6 }); | ||
const body = { | ||
event: { category, action, name, value, dimension6 }, | ||
userId: Matomo.userId, | ||
dimensions: Matomo.dimensions, | ||
}; | ||
API.post({ | ||
path: "/event", | ||
body, | ||
}); | ||
} catch (e) { | ||
console.log("logEvent error", e); | ||
console.log("logEvent error", { category, action, name, value, dimension6 }); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters