npm install @aysnet/qv-strapi
'or'
yarn add @aysnet/qv-strapi
import Vue from 'vue';
import Strapi from '@aysnet/qv-strapi';
const options = {
url:'', // by default : 'http://localhost:1337
storeConfig: {
cookie: {
key: 'jwt',
options: {
path: '/'
}
},
localStorage:{} // | boolean
},
requestConfig: '',
}
const strapi = new Strapi(options)
Vue.use(strapi)
import Vue from 'vue'
import Strapi from '@aysnet/qv-strapi';
const options = {
url:'', // by default : 'http://localhost:1337
storeConfig: {
cookie: {
key: 'jwt',
options: {
path: '/'
}
},
localStorage:{} // | boolean
},
requestConfig: '',
}
const strapi = new Strapi(options)
export default ({
Vue
}) => {
Vue.prototype.$strapi = strapi
}
export {
strapi
}
To handle authentication in your Vue / quasar app with Strapi, you can:
await this.$strapi.login({identifier:'email', password:'password'})
await this.$strapi.register({email:'email', username:'username', password:'password'} )
await this.$strapi.logout()
await this.$strapi.forgotPassword({email:'email'})
await this.$strapi.resetPassword({code:this.$route.query.code /*url*/, password:'password', passwordConfirmation:'passwordConfir..'})
Once logged in, you can access your user
everywhere:
<template>
<div>
<p v-if="$strapi.user">
Logged in
</p>
</div>
</template>
<script>
export default {
computed: {
user () {
return this.$strapi.user
}
},
methods: {
logout () {
this.$strapi.logout()
this.$router.push('/')
}
}
}
</script>
You can access the default Strapi CRUD operations by using these methods:
find
count
findByid
create
update
delete
searchFiles
findFile
findFiles
upload
fetch
await this.$strapi.find('products')
You often need to update your user, and so on define a custom route in Strapi: PUT /users/me
.
You can use this module to call it this way:
const user = await this.$strapi.$users.update('me', form)
And then mutate the user
:
this.$strapi.user = user
await strapi.login({identifier:'email', password:'password'});
// Redirect your user to the provider's authentication page.
window.location = strapi.getProviderAuthenticationUrl('facebook');
Once authorized, the provider will redirects the user to your app with an access token in the URL.
// Complete the authentication: (The SDK will store the access token for you)
await strapi.authenticateProvider('facebook');
You can now fetch private APIs
const posts = await strapi.find('posts');
const form = new FormData();
form.append('files', fileInputElement.files[0], 'file-name.ext');
form.append('files', fileInputElement.files[1], 'file-2-name.ext');
const files = await strapi.upload(form);
const FormData = require('form-data');
const fs = require('fs');
const form = new FormData();
form.append('files', fs.createReadStream('./file-name.ext'), 'file-name.ext');
const files = await strapi.upload(form, {
headers: form.getHeaders()
});
const DataQuery = await this.$strapi.graphql({
query: `
query {
classes {
title
user{
username
}
}
}
`
});
MIT