I use Strapi 3.0.1 version and I try to adjust the reset password for admin. If I understand correctly I need to set up only an email provider. I had read the doc for setting up email provider here
I had installed the strapi-provider-email-nodemailer and created a file ./config/plugins.js with
module.exports = ({ env }) => ({
email: {
provider: 'nodemailer',
providerOptions: {
host: "smtp.***.***",
port: 465,
secure: true,
auth: {
user: "***",
pass: "***",
}
},
settings: {
defaultFrom: '***',
defaultReplyTo: '***',
},
},
});
After that, I navigate to ****/admin/auth/forgot-password* and input admin email and get an error This email is invalid.
{
"statusCode": 400,
"error": "Bad Request",
"message": [{"messages": [{"id": "Auth.form.error.email.invalid"}]}],
"data": [{"messages": [{"id": "Auth.form.error.email.invalid"}]}]
}
Could you please help me to set up an email provider or find a mistake?
It works with settings:
module.exports = ({ env }) => ({
email: {
provider: "nodemailer",
providerOptions: {
nodemailer_default_from: "XXX",
nodemailer_default_replyto: "XXX",
host: env('EMAIL_HOST'),
port: env('EMAIL_PORT', 25),
password: env('EMAIL_PASSWORD'),
username: env('EMAIL_USERNAME'),
authMethod: "SMTP",
}
},
});
Related
Am trying to do a simple GET request in NuxtJs using Axios. l have configured my nuxt.config.js like this
axios: {
proxy: true,
credentials: true,
baseURL: 'http://localhost:8000/api/'
},
proxy: {
'/api': { target: 'http://localhost:8000', pathRewrite: {'^/api/v1/': ''} }
},
auth: {
strategies: {
laravelSanctum: {
provider: 'laravel/sanctum',
url: 'http://localhost:8000',
token: {
property: 'token',
global: true,
required: true,
type: 'Bearer',
name: 'Authorization'
},
refreshToken: {
property: 'token',
data: 'token',
maxAge: 60 * 60 * 24 * 30
},
user: {
property: 'user',
},
endpoints: {
login: { url: '/api/auth/login', method: 'post' },
user: { url: '/api/user', method: 'get' },
logout: { url: '/api/auth/logout', method: 'get' },
refresh: { url: '/api/refresh', method: 'get' },
},
tokenType: 'Bearer',
tokenRequired: true,
cookie: {
cookie: {
name: 'XSRF-TOKEN',
},
},
}
},
redirect: {
login: '/',
logout: '/',
callback: false,
home: '/'
},
},
router: {
middleware: 'auth'
},
l have tried alot of methods that were posted here before but no avail. Same issues. l also noticed that when l reload the page. Vuex shows user object empty.
Am using Laravel Sactum, any help will be greatly appreciated. Thanks in advance
I am facing a weird problem. I have a Laravel API server setup and a Nuxtjs frontend. I am using LaravelSanctum Provider in Nuxtjs. I am able to send request and the authentication and data retrival is fine. However, the cookies doesn't seem to get stored in my local storage.
login.vue
<script>
export default {
async login() {
this.$auth.loginWith('laravelSanctum', {
data: {
email: 'test#gmail.com',
password: 'test',
},
})
},
}
</script>
nuxt.config.js
axios: {
baseURL: 'http://local.api.test/api/v1/',
proxy: true,
credentials: true,
},
proxy: {
'/laravel': {
target: 'http://local.api.test/api/v1/',
pathRewrite: { '^/laravel': '/' },
},
},
auth: {
strategies: {
laravelSanctum: {
provider: 'laravel/sanctum',
url: 'http://local.api.test',
endpoints: {
login: {
url: '/api/v1/login/admin',
},
user: {
url: '/api/v1/admin',
},
},
},
},
},
Just trying to get a handle on Yup and unfortunately I can't seem to find any examples that point to validating a nested object and a nested array (of objects) within another object.
I have something like this:
"books": [{
"info": {
"dateReleased": null,
"timeReleased": null
},
"reviewers": [
{
"company": "",
"name": ""
}
]
}]
I just have no idea what the required Yup validation syntacx is for info and reviewers as all I want to validate is that the values are not null and are required.
I'vetried this but no validation is firing:
Yup.object().shape({
books: Yup.array(
info: Yup.object({
dateReleased: Yup.date().required('Rquired')
timeReleased: Yup.date().required('Required')
})
reviewers: Yup.array(
Yup.object({
company: Yup.string().required('Required')
name: Yup.string().required('Required')
})
)
)
})
With the above, I'm not getting any console errors but none of my validation rules for info and reviewers are firing.
Yup Validation
const value = {
books: [
{
info: {
dateReleased: null,
timeReleased: null,
},
reviewers: [
{
company: "",
name: "",
},
],
},
],
};
const schema = yup.object().shape({
books: yup.array(
yup.object().shape({
info: yup.object().shape({
dateReleased: yup.date().required('Required'),
timeReleased: yup.date().required('Required')
}),
reviewer: yup.array(
yup.object().shape({
company: yup.string().required('Required'),
name: yup.string().required('Required')
})
)
})
),
});
schema.validate(value).catch(err => {
console.log(err.name); // ValidationError
console.log(err.errors); // [books[0].info.timeReleased must be a `date` type, but the final value was: `Invalid Date`.]
});
I have one request that I want to get token from response and save it in variable because I want to use it in another request as bearer token
/// <reference types="cypress" />
describe("Testing API Endpoints Using Cypress", () => {
it("Login", () => {
cy.request({
method: "POST",
url: "/creditonal",
body: {
"credentials": {
"username": "admin",
"password": "admin"
}
}.then((response) => {
// Get token
})
})
})
})
This is my response
{
"status": "ok",
"statusCode": "0000",
"message": {
"type": "",
"text": ""
},
"errors": [],
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVmYTk0YzYzNWRhOWU0NTY0NGYwM2ViMiIsImlzQ2xpZW50IjpmYWxzZSwiaWF0IjoxNjExMjQzNjYyLCJleHBBdCI6MTYxMTI0NzI2MiwiaXNzdWVyIjoiRHJvcHAgVGVjaG5vbG9naWVzIiwicm9sZXMiOlsiRVJ5eGc2Il19.V7cniqE9DrxPRn5GX9wQJtVwPnLrv5Hb3A1SxmBXOO4",
"accessTokenExpiresAt": 3599,
"refreshToken": "983e503a2b194a0190af4cdf0f4d471cf387e4d784044f6ca1fe3f942aad1b5f",
"refreshTokenExpiresAt": 15548399
}
}
You can use token from from request 1 and pass it onto request 2 like this. I have currently used the token as an bearer authorization header.
cy.request({
method: "POST",
url: "/creditonal",
body: {
"credentials": {
"username": "admin",
"password": "admin"
}
}
}).then((response) => {
const token = response.data.accessToken
return token
}).then((token) => {
//Use the value of token anywhere in the second request anywhere
cy.request({
method: 'GET',
url: 'https//example.com',
'auth': {
'bearer': token
}
}).then((response) => {
expect(response.status).to.eq(200)
})
})
I would suggest to go for alias which is easier to use. You just retrieve the response whenever you really need:
it("Login", () => {
cy.request({
method: "POST",
url: "/creditonal",
body: {
"credentials": {
"username": "admin",
"password": "admin"
}
}
}).as('login')
// do more things
cy.get('#login').then(response => {
// whatever you want with response later on
})
})
I created a model with validation like below:
sequelize
.define('Email',
{
email: { type: DataTypes.STRING, allowNull: false, unique:false, defaultValue: 'placeholder',
validate: {
isEmail: true,
}
}
});
If I try and create an email with an empty 'email' field, it generates this error:
{
"error": {
"__raw": [
null
],
"email": [
"Validation isEmail failed"
]
}
What is the __raw field and how can I remove it?
Try this validation
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
emailValidation: function() {
var pattern = /^[a-zA-Z0-9\-_]+(\.[a-zA-Z0-9\-_]+)*#[a-z0-9]+(\-[a-z0-9]+)*(\.[a-z0-9]+(\-[a-z0-9]+)*)*\.[a-z]{2,4}$/;
if(!pattern.test(this.email)) {
throw new Error('INVALID_EMAIL');
}
}
}
}
Hope this is helpful