mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-05-19 00:12:00 +00:00
Fix authorize function
This commit is contained in:
parent
a794755df4
commit
129cbd02e2
@ -1,14 +1,14 @@
|
|||||||
// datasource db {
|
|
||||||
// provider = "postgresql"
|
|
||||||
// url = env("DATABASE_URL")
|
|
||||||
// }
|
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "postgresql"
|
provider = "postgresql"
|
||||||
url = env("POSTGRES_PRISMA_URL")
|
url = env("DATABASE_URL")
|
||||||
directUrl = env("POSTGRES_URL_NON_POOLING")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// datasource db {
|
||||||
|
// provider = "postgresql"
|
||||||
|
// url = env("POSTGRES_PRISMA_URL")
|
||||||
|
// directUrl = env("POSTGRES_URL_NON_POOLING")
|
||||||
|
// }
|
||||||
|
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,6 @@ const CoursePaymentButton = ({ lnAddress, amount, onSuccess, onError, courseId }
|
|||||||
const result = await axios.post('/api/purchase/course', purchaseData);
|
const result = await axios.post('/api/purchase/course', purchaseData);
|
||||||
|
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
showToast('success', 'Payment Successful', `Paid ${amount} sats and updated user purchases`);
|
|
||||||
if (onSuccess) onSuccess(response);
|
if (onSuccess) onSuccess(response);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Failed to update user purchases');
|
throw new Error('Failed to update user purchases');
|
||||||
|
@ -73,7 +73,6 @@ const ResourcePaymentButton = ({ lnAddress, amount, onSuccess, onError, resource
|
|||||||
const result = await axios.post('/api/purchase/resource', purchaseData);
|
const result = await axios.post('/api/purchase/resource', purchaseData);
|
||||||
|
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
showToast('success', 'Payment Successful', `Paid ${amount} sats and updated user purchases`);
|
|
||||||
if (onSuccess) onSuccess(response);
|
if (onSuccess) onSuccess(response);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Failed to update user purchases');
|
throw new Error('Failed to update user purchases');
|
||||||
|
@ -10,7 +10,7 @@ const localRatelimit = {
|
|||||||
limit: async (key) => {
|
limit: async (key) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const windowMs = 10 * 1000; // 10 seconds
|
const windowMs = 10 * 1000; // 10 seconds
|
||||||
const maxRequests = 20;
|
const maxRequests = 25;
|
||||||
|
|
||||||
const requestLog = inMemoryStore.get(key) || [];
|
const requestLog = inMemoryStore.get(key) || [];
|
||||||
const windowStart = now - windowMs;
|
const windowStart = now - windowMs;
|
||||||
@ -36,7 +36,7 @@ const localRatelimit = {
|
|||||||
const ratelimit = process.env.NODE_ENV === 'production'
|
const ratelimit = process.env.NODE_ENV === 'production'
|
||||||
? new Ratelimit({
|
? new Ratelimit({
|
||||||
redis: kv,
|
redis: kv,
|
||||||
limiter: Ratelimit.slidingWindow(20, '10 s'),
|
limiter: Ratelimit.slidingWindow(25, '10 s'),
|
||||||
analytics: true,
|
analytics: true,
|
||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
})
|
})
|
||||||
|
@ -29,21 +29,22 @@ const authorize = async (pubkey) => {
|
|||||||
if (dbUser) {
|
if (dbUser) {
|
||||||
const fields = await findKind0Fields(profile);
|
const fields = await findKind0Fields(profile);
|
||||||
// Only update 'avatar' or 'username' if they are different from kind0 fields on the dbUser
|
// Only update 'avatar' or 'username' if they are different from kind0 fields on the dbUser
|
||||||
const updatedFields = ['avatar', 'username'].reduce((acc, key) => {
|
if (fields.avatar !== dbUser.avatar) {
|
||||||
if (fields[key] !== dbUser[key]) {
|
const updatedUser = await updateUser(dbUser.id, { avatar: fields.avatar });
|
||||||
acc[key] = fields[key];
|
if (updatedUser) {
|
||||||
|
dbUser = await getUserByPubkey(pubkey);
|
||||||
|
}
|
||||||
|
} else if (fields.username !== dbUser.username) {
|
||||||
|
const updatedUser = await updateUser(dbUser.id, { username: fields.username });
|
||||||
|
if (updatedUser) {
|
||||||
|
dbUser = await getUserByPubkey(pubkey);
|
||||||
}
|
}
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
// if there are updated fields, update the user only with the updated fields
|
|
||||||
if (Object.keys(updatedFields).length > 0) {
|
|
||||||
dbUser = await updateUser(dbUser.id, updatedFields);
|
|
||||||
}
|
}
|
||||||
|
// add the kind0 fields to the user
|
||||||
// Combine user object with kind0Fields, giving priority to kind0Fields
|
|
||||||
const combinedUser = { ...dbUser, kind0: fields };
|
const combinedUser = { ...dbUser, kind0: fields };
|
||||||
|
|
||||||
|
console.log("COMBINED USER", combinedUser);
|
||||||
|
|
||||||
return combinedUser;
|
return combinedUser;
|
||||||
} else {
|
} else {
|
||||||
// Create user
|
// Create user
|
||||||
|
@ -191,6 +191,7 @@ const Course = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handlePaymentSuccess = async (response) => {
|
const handlePaymentSuccess = async (response) => {
|
||||||
|
console.log("response in handlePaymentSuccess", response);
|
||||||
if (response && response?.preimage) {
|
if (response && response?.preimage) {
|
||||||
const updated = await update();
|
const updated = await update();
|
||||||
console.log("session after update", updated);
|
console.log("session after update", updated);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user