W
Wasp-lang2mo ago
2euxs

S3 files can't update

Hi everyone ! Im using the File Upload demo with opensaas but when I delete files directly in the s3, it do not update in the app. Do you know anyway I could fix that ?
No description
No description
6 Replies
kapa.ai
kapa.ai2mo ago
Hi @2euxs. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. However, it's important to note that deleting files directly from S3 might not update the app because the app might not be aware of the changes made directly in the S3 bucket. You might need to implement a mechanism in your app to sync with the S3 bucket or handle the deletion of files from within the app itself, so it can update its own state accordingly. For more information on file handling with Wasp and OpenSaaS, you can refer to this guide: OpenSaaS File Uploading Guide (https://docs.opensaas.sh/guides/file-uploading/). For more specific help, you might want to ask this question in the Wasp community on Discord. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @2euxs, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho2mo ago
Kapa is on the right track, there should be a sync mechanism between the app and S3. I'm not sure if S3 exposes a webhook e.g. onFileDelete or you'll need to use the S3 API to get the list of files each time to keep them in sync with your app.
2euxs
2euxs2mo ago
thank you
MEE6
MEE62mo ago
Wohooo @2euxs, you just became a Waspeteer level 1!
2euxs
2euxs2mo ago
@kapa.ai How can I get user id
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- In Wasp, you can get the user ID in several ways depending on where you need it. 1. On the server: When authentication is enabled, all queries and actions have access to the user object through the context argument. context.user contains all User entity's fields and the auth identities connected to the user. Here is an example:
export const createTask = async (task, context) => {
if (!context.user) {
throw new HttpError(403)
}

const Task = context.entities.Task
return Task.create({
data: {
description: task.description,
user: {
connect: { id: context.user.id },
},
},
})
}
export const createTask = async (task, context) => {
if (!context.user) {
throw new HttpError(403)
}

const Task = context.entities.Task
return Task.create({
data: {
description: task.description,
user: {
connect: { id: context.user.id },
},
},
})
}
In this example, context.user.id is used to get the user ID. source (https://wasp-lang.dev/docs/auth/overview#using-the-contextuser-object) 2. On the client: You can use the user prop or the useAuth hook to access the user object. Here is an example using the useAuth hook:
import { useAuth, logout } from 'wasp/client/auth'

export function Main() {
const { data: user } = useAuth()

if (!user) {
return (
<span>
Please <Link to="/login">login</Link> or{' '}
<Link to="/signup">sign up</Link>.
</span>
)
} else {
return (
<>
<button onClick={logout}>Logout</button>
<Todo />
</>
)
}
}
import { useAuth, logout } from 'wasp/client/auth'

export function Main() {
const { data: user } = useAuth()

if (!user) {
return (
<span>
Please <Link to="/login">login</Link> or{' '}
<Link to="/signup">sign up</Link>.
</span>
)
} else {
return (
<>
<button onClick={logout}>Logout</button>
<Todo />
</>
)
}
}
In this example, user.id would give you the user ID. source (https://wasp-lang.dev/docs/auth/overview#using-the-useauth-hook) Remember, the user object contains all the fields that you defined in your User entity, plus the auth field which contains the auth identities connected to the user. source (https://wasp-lang.dev/docs/auth/overview#accessing-the-logged-in-user) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @2euxs, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Want results from more Discord servers?
Add your server