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