JLegendz
JLegendz
WWasp-lang
Created by JLegendz on 7/20/2024 in #πŸ™‹questions
Deployment Questions
Hi! I'm getting very close to deploying, and I have a few questions before I do. As a bit of context, I'm an experienced web developer but I've never launched my own application. 1. Updates: Is there a recommended way to push updates to the live version of the wasp application? Currently I'm hosting everything on github, and would like to use my main branch as the deployed version of the app. What's best practice here? 2. Prisma DB Studio access for deployed app. How would I go about accessing this to manage the data for my app? 3. Substituting NGROK. Currently, I'm using Ngrok to test my endpoints from a mobile version of my app, but I'll need to swap that out for whatever will replace my port 3000 and 3001. I'm not sure what to expect when I cross that road. I plan to deploy in the next two days and I'm excited! But I know I'll need to be able to keep pushing updates and I'm not sure how that all works just yet. Thanks!
9 replies
WWasp-lang
Created by JLegendz on 6/2/2024 in #πŸ™‹questions
Stripe event for onMonthlyContinuation of subscription?
In the open-saas template there's the one time payment option to receive 10 credits. I'm making one of my tiers come with 50 credits per month. What's the recommended way to check for if the payment for the next month has been received so that I can add 50 more credits to the user's account?
6 replies
WWasp-lang
Created by JLegendz on 5/31/2024 in #πŸ™‹questions
useQuery server side?
I am trying to use one of my queries inside of my websocket server but when I do, the context.user doesn't exist. Even if I make sure that I'm calling this query after the user is authenticated. I'm not sure why context.user isn't populated, but it got me to thinking if maybe I should only be using the queries from the client side? Surely there's a way to do it server side though? I have this query: app/src/server/queries.ts
export const getSubscriptionsByUser: GetSubscriptionsByUser<void, Subscription[]> = async (args, context) => {
if (!context.user) {
throw new HttpError(401);
}

return context.entities.Subscription.findMany({
where: {
userId: context.user.id,
},
include: {
listing: true,
},
});
};
export const getSubscriptionsByUser: GetSubscriptionsByUser<void, Subscription[]> = async (args, context) => {
if (!context.user) {
throw new HttpError(401);
}

return context.entities.Subscription.findMany({
where: {
userId: context.user.id,
},
include: {
listing: true,
},
});
};
and in my ws-server.ts I'm attempting to use it like this.
import { getListingSubscribers, getSubscriptionsByUser } from './queries'; // Import the getListingSubscribers function

//Skipping a bunch of unrelated code...

socket.on('userAuthenticated', async () => {
console.log('User authenticated:', username);

// Check if the user is authenticated before trying to rejoin rooms
if (socket.data.user) {
try {
//TODO There is an error here. context.user doesn't exist and so we can't fetch subscriptions here.
// It's all happening before the user is fully authenticated apparently.
const subscriptions = await getSubscriptionsByUser(undefined, context);
subscriptions.forEach(sub => {
const room = `listing_${sub.listingId}`;
socket.join(room);
console.log(`${username} rejoined room ${room}`);
});
} catch (error) {
console.error('Error rejoining rooms:', error);
}
} else {
console.warn('User not authenticated, skipping room rejoining.');
}
});
import { getListingSubscribers, getSubscriptionsByUser } from './queries'; // Import the getListingSubscribers function

//Skipping a bunch of unrelated code...

socket.on('userAuthenticated', async () => {
console.log('User authenticated:', username);

// Check if the user is authenticated before trying to rejoin rooms
if (socket.data.user) {
try {
//TODO There is an error here. context.user doesn't exist and so we can't fetch subscriptions here.
// It's all happening before the user is fully authenticated apparently.
const subscriptions = await getSubscriptionsByUser(undefined, context);
subscriptions.forEach(sub => {
const room = `listing_${sub.listingId}`;
socket.join(room);
console.log(`${username} rejoined room ${room}`);
});
} catch (error) {
console.error('Error rejoining rooms:', error);
}
} else {
console.warn('User not authenticated, skipping room rejoining.');
}
});
The end goal of all this is to emit a signal when the user is authenticated, so that I can make sure that context.user exists, and then I can add the user back into any websocket rooms they belong to as a way to persist that connection between server restarts during development. I always get a 401 no matter what though, and context.user just doesn't exist. Any suggestions here? I'm not sure what I'm doing wrong.
7 replies
WWasp-lang
Created by JLegendz on 5/30/2024 in #πŸ™‹questions
Safe to do major prisma update?
My console informed me that there is a major Prima update available. Is it safe to update?
[ Db !] β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
[ Db !] β”‚ Update available 4.16.2 -> 5.14.0 β”‚
[ Db !] β”‚ β”‚
[ Db !] β”‚ This is a major update - please follow the guide at β”‚
[ Db !] β”‚ https://pris.ly/d/major-version-upgrade β”‚
[ Db !] β”‚ β”‚
[ Db !] β”‚ Run the following to update β”‚
[ Db !] β”‚ npm i --save-dev prisma@latest β”‚
[ Db !] β”‚ npm i @prisma/client@latest β”‚
[ Db !] β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
[ Db !] β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
[ Db !] β”‚ Update available 4.16.2 -> 5.14.0 β”‚
[ Db !] β”‚ β”‚
[ Db !] β”‚ This is a major update - please follow the guide at β”‚
[ Db !] β”‚ https://pris.ly/d/major-version-upgrade β”‚
[ Db !] β”‚ β”‚
[ Db !] β”‚ Run the following to update β”‚
[ Db !] β”‚ npm i --save-dev prisma@latest β”‚
[ Db !] β”‚ npm i @prisma/client@latest β”‚
[ Db !] β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
8 replies
WWasp-lang
Created by JLegendz on 5/28/2024 in #πŸ™‹questions
API Authentication
Is there a good example of how to add an api endpoint for authentication? I'm primarily using username and password for now but eventually I'd like make use of all the authentication methods provided by wasp, but through an api.
64 replies
WWasp-lang
Created by JLegendz on 5/28/2024 in #πŸ™‹questions
Accessing API endpoing from postman
After following the API tutorial, I attempted to post a GET request to http://localhost:3000/foo/bar and the response is just the web-app/index.html file. When following the tutorial example of using the api from the client, I successfully get my data: import React, { useEffect } from "react"; import { api } from "wasp/client/api"; async function fetchCustomRoute() { const res = await api.get("/foo/bar"); console.log(res.data); } export const Foo = () => { useEffect(() => { fetchCustomRoute(); }, []); return <>// ...</>; }; But I'm still not able to get it from postman, am I misunderstanding something?
14 replies
WWasp-lang
Created by JLegendz on 5/27/2024 in #πŸ™‹questions
websocket definition?
I've been trying to follow along with https://wasp-lang.dev/blog/2023/08/09/build-real-time-voting-app-websockets-react-typescript and https://wasp-lang.dev/docs/advanced/web-sockets to get websockets working with the open-saas demo app template. When I attempt to use
import { WebSocketDefinition } from '@wasp/webSocket';
import { WebSocketDefinition } from '@wasp/webSocket';
in my app/src/server/ws-server.ts file, it's not able to find wasp/websocket. I searched and it doesn't appear to exist but I'm hoping I'm wrong. Are websockets setup to work on the open saas template?
10 replies
WWasp-lang
Created by JLegendz on 5/27/2024 in #πŸ™‹questions
New user fields not recognized
I'm attempting to add some attributes to my user entity that have a relation to other entity attributes.
entity User {=psl
id Int @id @default(autoincrement())
createdAt DateTime @default(now())

email String? @unique
username String? @unique
lastActiveTimestamp DateTime @default(now())
isAdmin Boolean @default(false)

stripeId String?
checkoutSessionId String?
subscriptionTier String?
subscriptionStatus String?
sendEmail Boolean @default(false)
datePaid DateTime?
credits Int @default(3)

gptResponses GptResponse[]
contactFormMessages ContactFormMessage[]
tasks Task[]
files File[]

subscriptions Listing[] @relation("UserSubscriptions")
listings Listing[]
advertisements Advertisement[]
claims Advertisement[] @relation("UserClaims")

psl=}
entity User {=psl
id Int @id @default(autoincrement())
createdAt DateTime @default(now())

email String? @unique
username String? @unique
lastActiveTimestamp DateTime @default(now())
isAdmin Boolean @default(false)

stripeId String?
checkoutSessionId String?
subscriptionTier String?
subscriptionStatus String?
sendEmail Boolean @default(false)
datePaid DateTime?
credits Int @default(3)

gptResponses GptResponse[]
contactFormMessages ContactFormMessage[]
tasks Task[]
files File[]

subscriptions Listing[] @relation("UserSubscriptions")
listings Listing[]
advertisements Advertisement[]
claims Advertisement[] @relation("UserClaims")

psl=}
subscriptions and claims are the new addition I'm adding. On one of my pages where I'm already reading user.credits, I'm also trying to read user.subscriptions, but I get the following error: [ Wasp ] ext-src/client/app/ListingDetailsPage.tsx(61,25): error TS2551: Property 'subscriptions' does not exist on type 'AuthUser'. Did you mean 'subscriptionTier'?
40 replies
WWasp-lang
Created by JLegendz on 5/26/2024 in #πŸ™‹questions
React Native Integration
My SAAS app will have a mobile version. I'm using the dummy starter project for the web app, but when the time comes, I'll need to be able to do crud operations from my react native app. I know open-saas has a lot under the hood that makes web app development faster, but can I leverage any of this for my react-native app? I'm worried about how I might connect the mobile app to this one.
6 replies
WWasp-lang
Created by JLegendz on 5/26/2024 in #πŸ™‹questions
adding node packages
Are there any special considerations when adding node packages to the dummy app starter template? Do I just wrong the npm install cli command and I’m good or is there more that I need to do? Asking before I make a mess lol.
6 replies
WWasp-lang
Created by JLegendz on 5/26/2024 in #πŸ™‹questions
New Wasp Entity Attributes Not included in CreateEntityName function
I have an Entity that I've added new attributes to. I've done this several times without any issues. But now, I've added a few attributes and i've run the command to refresh the db. But when I attempt to use the createEntityName function elsewhere, my new attributes aren't allowed as arguments.
12 replies
WWasp-lang
Created by JLegendz on 5/25/2024 in #πŸ™‹questions
Get Download URL After Upload
Using the provided template, I'm having a hard time figuring out a good way to get the download url after uploading a file to s3. I know the template lists all of a user's files with a download button, but the logic there is a little confusing to follow. I have a form that uses the file upload functionality and that works fine, but I need to capture the download url before the form "submits". Could someone give me a hand with this? Lol even chatgpt doesn't handle this so well. For context, I have a form to upload a post. The image for it needs to upload, provide a download link, that I can then store when I createPost(). Thanks in advance. And sorry if it's a noob question.
24 replies
WWasp-lang
Created by JLegendz on 5/24/2024 in #πŸ™‹questions
File Upload (Tutorial Follow Along)
Hi! I'm following along with the tutorial https://docs.opensaas.sh/guides/file-uploading/ and I'm getting a 403 error after adding my IAM and S3 credentials to my .env.server
{
"message": "Request failed with status code 403",
"name": "AxiosError",
"stack": "AxiosError: Request failed with status code 403\n at settle (http://localhost:3000/node_modules/.vite/deps/axios.js?v=3e43de8b:1203:12)\n at XMLHttpRequest.onloadend (http://localhost:3000/node_modules/.vite/deps/axios.js?v=3e43de8b:1420:7)\n at Axios.request (http://localhost:3000/node_modules/.vite/deps/axios.js?v=3e43de8b:1780:41)\n at async handleUpload (http://localhost:3000/@fs/home/jparker/my_apps/sass_one/advertiser/app/src/client/app/FileUploadPage.tsx:62:19)",
"config": {
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
},
"adapter": [
"xhr",
"http"
],
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"env": {},
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "image/jpeg"
},
"method": "put",
"url": "https://hereqr1.s3.us-east-2.amazonaws.com/2/6b13aab3-114d-4b7f-ab0b-640b2899204f.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=[REDACTED]%2F20240524%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20240524T024414Z&X-Amz-Expires=3600&X-Amz-Signature=77f03e27f916b8e19612cb1d535b69a3c92b6a084de0f283d0ebfa401f34bdcf&X-Amz-SignedHeaders=host&x-id=PutObject",
"data": {}
},
"code": "ERR_BAD_REQUEST",
"status": 403
}
{
"message": "Request failed with status code 403",
"name": "AxiosError",
"stack": "AxiosError: Request failed with status code 403\n at settle (http://localhost:3000/node_modules/.vite/deps/axios.js?v=3e43de8b:1203:12)\n at XMLHttpRequest.onloadend (http://localhost:3000/node_modules/.vite/deps/axios.js?v=3e43de8b:1420:7)\n at Axios.request (http://localhost:3000/node_modules/.vite/deps/axios.js?v=3e43de8b:1780:41)\n at async handleUpload (http://localhost:3000/@fs/home/jparker/my_apps/sass_one/advertiser/app/src/client/app/FileUploadPage.tsx:62:19)",
"config": {
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
},
"adapter": [
"xhr",
"http"
],
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"env": {},
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "image/jpeg"
},
"method": "put",
"url": "https://hereqr1.s3.us-east-2.amazonaws.com/2/6b13aab3-114d-4b7f-ab0b-640b2899204f.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=[REDACTED]%2F20240524%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20240524T024414Z&X-Amz-Expires=3600&X-Amz-Signature=77f03e27f916b8e19612cb1d535b69a3c92b6a084de0f283d0ebfa401f34bdcf&X-Amz-SignedHeaders=host&x-id=PutObject",
"data": {}
},
"code": "ERR_BAD_REQUEST",
"status": 403
}
15 replies