Generate prayer ID on server to fix crypto.randomUUID browser compat
Older browsers (and non-HTTPS contexts) don't have crypto.randomUUID. Move ID generation to the server using Node's built-in crypto module. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DReRqHxSYuVfCzTzQGD9hZ
This commit is contained in:
2 files changed
+3
-3
No files matched your search
@@ -2,6 +2,7 @@ const express = require('express');
|
|||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const { randomUUID } = require('crypto');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const DATA_DIR = process.env.DATA_DIR || path.join(__dirname, 'data');
|
const DATA_DIR = process.env.DATA_DIR || path.join(__dirname, 'data');
|
||||||
@@ -50,7 +51,7 @@ app.get('/api/prayers', (req, res) => {
|
|||||||
app.post('/api/prayers', (req, res) => {
|
app.post('/api/prayers', (req, res) => {
|
||||||
try {
|
try {
|
||||||
const prayers = readPrayers();
|
const prayers = readPrayers();
|
||||||
const prayer = req.body;
|
const prayer = { id: randomUUID(), ...req.body };
|
||||||
prayers.unshift(prayer);
|
prayers.unshift(prayer);
|
||||||
writePrayers(prayers);
|
writePrayers(prayers);
|
||||||
res.status(201).json(prayer);
|
res.status(201).json(prayer);
|
||||||
|
|||||||
+1
-2
@@ -25,8 +25,7 @@ export function usePrayers() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const addPrayer = useCallback(async (request: string, tags: string[]) => {
|
const addPrayer = useCallback(async (request: string, tags: string[]) => {
|
||||||
const prayer: Prayer = {
|
const prayer = {
|
||||||
id: crypto.randomUUID(),
|
|
||||||
request,
|
request,
|
||||||
answer: '',
|
answer: '',
|
||||||
status: 'active',
|
status: 'active',
|
||||||
|
|||||||
Reference in new issue
Block a user