Hello!
Re-factored a bunch of my app with everything from your Laravel API book and it’s going GREAT! Faster, easier to read, efficient - love it.
Running into a bit of a snag with Laravel Vapor - which I understand you might not know fully - but since I’m running into a CSRF issue, I’m pretty sure you might have some ideas.
You can read here in the Laravel Vapor Docs about File Uploads. Essentially, it consists of loading a package and then making this call, to temporarily store your file on AWS:
Vapor.store(this.$refs.file.files[0], {
progress: progress => {
this.uploadProgress = Math.round(progress * 100);
}
}).then(response => {
axios.post('/api/profile-photo', {
uuid: response.uuid,
key: response.key,
bucket: response.bucket,
name: this.$refs.file.files[0].name,
content_type: this.$refs.file.files[0].type,
})
});
My problem is this - it works GREAT locally, I can upload, do whatever I want with, etc. When I upload it to production it fails.
At first it was calling the wrong domain by posting to the frontend domain, instead of the API domain. So I added a baseURL
option:
Vapor.store(this.$refs.file.files[0], {
progress: progress => {
this.uploadProgress = Math.round(progress * 100);
},
baseURL: this.storageUrl,
})
where storageURL
is my Laravel API server.
That got rid of the 404, but NOW I’m getting the dreaded 419 CSRF token mismatch that users of Laravel Sanctum are so familiar with
I tried adding this as an option as well:
headers: {
credentials: true,
withCredentials: true
}
with no joy.
Any ideas??
The relevant file from the laravel-vapor npm repo just looks like this:
async store(file, options = {}) {
const response = await axios.post('/vapor/signed-storage-url', {
'bucket': options.bucket || '',
'content_type': options.contentType || file.type,
'expires': options.expires || '',
'visibility': options.visibility || ''
}, {
baseURL: options.baseURL || null,
headers: options.headers || {},
...options.options
});
Thank you in advance for your expertise!