Improve user authentication and bid data handling
Standardizes user ID retrieval across multiple API endpoints and formats bid amount to string in the client. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 069d4324-6c40-4355-955e-c714a50de1ea Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3df548ff-50ae-432f-9be4-25d34eccc983/069d4324-6c40-4355-955e-c714a50de1ea/YptCfK0
This commit is contained in:
4
.replit
4
.replit
@ -22,6 +22,10 @@ externalPort = 3002
|
|||||||
localPort = 37531
|
localPort = 37531
|
||||||
externalPort = 3001
|
externalPort = 3001
|
||||||
|
|
||||||
|
[[ports]]
|
||||||
|
localPort = 39291
|
||||||
|
externalPort = 3003
|
||||||
|
|
||||||
[[ports]]
|
[[ports]]
|
||||||
localPort = 43349
|
localPort = 43349
|
||||||
externalPort = 3000
|
externalPort = 3000
|
||||||
|
|||||||
@ -37,7 +37,11 @@ export default function MediaOutletAuction() {
|
|||||||
|
|
||||||
const placeBidMutation = useMutation({
|
const placeBidMutation = useMutation({
|
||||||
mutationFn: async (bidData: { amount: number; qualityScore?: number }) => {
|
mutationFn: async (bidData: { amount: number; qualityScore?: number }) => {
|
||||||
return apiRequest("POST", `/api/media-outlets/${params?.slug}/auction/bids`, bidData);
|
const formattedData = {
|
||||||
|
amount: bidData.amount.toString(),
|
||||||
|
qualityScore: bidData.qualityScore
|
||||||
|
};
|
||||||
|
return apiRequest("POST", `/api/media-outlets/${params?.slug}/auction/bids`, formattedData);
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@ -180,7 +180,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
|
|
||||||
app.post('/api/auctions/:id/bid', isAuthenticated, async (req: any, res) => {
|
app.post('/api/auctions/:id/bid', isAuthenticated, async (req: any, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.user.claims.sub;
|
const userId = req.user.claims?.sub || req.user.id;
|
||||||
const bidData = insertBidSchema.parse({
|
const bidData = insertBidSchema.parse({
|
||||||
...req.body,
|
...req.body,
|
||||||
auctionId: req.params.id,
|
auctionId: req.params.id,
|
||||||
@ -207,7 +207,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
return res.status(404).json({ message: "No active auction found for this media outlet" });
|
return res.status(404).json({ message: "No active auction found for this media outlet" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = req.user.claims.sub;
|
const userId = req.user.claims?.sub || req.user.id;
|
||||||
const bidData = insertBidSchema.parse({
|
const bidData = insertBidSchema.parse({
|
||||||
...req.body,
|
...req.body,
|
||||||
auctionId: auction.id,
|
auctionId: auction.id,
|
||||||
@ -225,7 +225,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
// Prediction market betting endpoints
|
// Prediction market betting endpoints
|
||||||
app.post('/api/prediction-markets/:marketId/bets', isAuthenticated, async (req: any, res) => {
|
app.post('/api/prediction-markets/:marketId/bets', isAuthenticated, async (req: any, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.user.claims.sub;
|
const userId = req.user.claims?.sub || req.user.id;
|
||||||
const { side, amount } = req.body;
|
const { side, amount } = req.body;
|
||||||
|
|
||||||
// Validate request
|
// Validate request
|
||||||
@ -258,7 +258,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
// Media outlet request routes
|
// Media outlet request routes
|
||||||
app.get('/api/media-outlet-requests', isAuthenticated, async (req: any, res) => {
|
app.get('/api/media-outlet-requests', isAuthenticated, async (req: any, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.user.claims.sub;
|
const userId = req.user.claims?.sub || req.user.id;
|
||||||
const user = await storage.getUser(userId);
|
const user = await storage.getUser(userId);
|
||||||
|
|
||||||
if (!user || user.role !== 'superadmin') {
|
if (!user || user.role !== 'superadmin') {
|
||||||
@ -276,7 +276,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
|
|
||||||
app.post('/api/media-outlet-requests', isAuthenticated, async (req: any, res) => {
|
app.post('/api/media-outlet-requests', isAuthenticated, async (req: any, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.user.claims.sub;
|
const userId = req.user.claims?.sub || req.user.id;
|
||||||
const requestData = insertMediaOutletRequestSchema.parse({
|
const requestData = insertMediaOutletRequestSchema.parse({
|
||||||
...req.body,
|
...req.body,
|
||||||
requesterId: userId
|
requesterId: userId
|
||||||
@ -292,7 +292,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
|
|
||||||
app.patch('/api/media-outlet-requests/:id', isAuthenticated, async (req: any, res) => {
|
app.patch('/api/media-outlet-requests/:id', isAuthenticated, async (req: any, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.user.claims.sub;
|
const userId = req.user.claims?.sub || req.user.id;
|
||||||
const user = await storage.getUser(userId);
|
const user = await storage.getUser(userId);
|
||||||
|
|
||||||
if (!user || user.role !== 'superadmin') {
|
if (!user || user.role !== 'superadmin') {
|
||||||
@ -321,7 +321,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
|
|
||||||
app.post('/api/articles/:articleId/comments', isAuthenticated, async (req: any, res) => {
|
app.post('/api/articles/:articleId/comments', isAuthenticated, async (req: any, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.user.claims.sub;
|
const userId = req.user.claims?.sub || req.user.id;
|
||||||
const commentData = insertCommentSchema.parse({
|
const commentData = insertCommentSchema.parse({
|
||||||
...req.body,
|
...req.body,
|
||||||
articleId: req.params.articleId,
|
articleId: req.params.articleId,
|
||||||
@ -339,7 +339,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
// Analytics routes
|
// Analytics routes
|
||||||
app.get('/api/analytics', isAuthenticated, async (req: any, res) => {
|
app.get('/api/analytics', isAuthenticated, async (req: any, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.user.claims.sub;
|
const userId = req.user.claims?.sub || req.user.id;
|
||||||
const user = await storage.getUser(userId);
|
const user = await storage.getUser(userId);
|
||||||
|
|
||||||
if (!user || (user.role !== 'admin' && user.role !== 'superadmin')) {
|
if (!user || (user.role !== 'admin' && user.role !== 'superadmin')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user