Bootstrap users in Magnoila CMS - magnolia

I'm working with Magnolia CMS and using bootstrapping to load initial system data.
I would like to load users like other data from YAML file, but the problem is that users are divided by folders (system and admin). So I can't load file with users in a particular folder ("admin" in my case) with bootstrapping, because the system creates this folder by itself.
If I mention "admin" folder in the file as root for user - the system will tell me, that folder with this UUID was already created or create a duplication folder, which will not work - users will not be visible and not be able to authenticate in the system.
How should I write YAML file to successfully load users in admin folder or it is not possible this way?
Here example of a bootstrap file I used:
'UserAdmin':
'email': ''
'enabled': true
'jcr:primaryType': 'mgnl:user'
'jcr:uuid': '55597d39-55bd-4bf2-9dfc-1a126759e4ed'
'jcrName': 'UserAdmin'
'language': 'en'
'mgnl:created': 2023-01-16T12:26:14.217Z
'mgnl:createdBy': 'superuser'
'mgnl:lastModified': 2023-01-16T12:26:14.786Z
'mgnl:lastModifiedBy': 'superuser'
'name': 'UserAdmin'
'pswd': '$2a$12$QWfP5723N1PLenH3rEOZ2.MS5WTkxxGHdk1eHmHP2A8CvOW3l3BAm'
'title': ''
'acl_users':
'jcr:uuid': 'eeb6745e-ad9b-4620-84c1-6585a8844c2d'
'mgnl:created': 2023-01-16T12:26:14.643Z
'mgnl:createdBy': 'superuser'
'mgnl:lastModified': 2023-01-16T12:26:14.643Z
'mgnl:lastModifiedBy': 'superuser'
'0':
'jcr:uuid': '22b5970a-029a-41dc-8126-317da7c2fd95'
'mgnl:created': 2023-01-16T12:26:14.645Z
'mgnl:createdBy': 'superuser'
'mgnl:lastModified': 2023-01-16T12:26:14.645Z
'mgnl:lastModifiedBy': 'superuser'
'path': '/admin/UserAdmin'
'permissions': 8
'00':
'jcr:uuid': '83950dba-2678-443d-b58b-95a8b44559a1'
'mgnl:created': 2023-01-16T12:26:14.648Z
'mgnl:createdBy': 'superuser'
'mgnl:lastModified': 2023-01-16T12:26:14.648Z
'mgnl:lastModifiedBy': 'superuser'
'path': '/admin/UserAdmin/email'
'permissions': 63
'01':
'jcr:uuid': '8c4bdad5-ff53-4931-b006-690347ca5a75'
'mgnl:created': 2023-01-16T12:26:14.651Z
'mgnl:createdBy': 'superuser'
'mgnl:lastModified': 2023-01-16T12:26:14.651Z
'mgnl:lastModifiedBy': 'superuser'
'path': '/admin/UserAdmin/language'
'permissions': 63
'02':
'jcr:uuid': 'e6f18601-a08b-491c-9f3f-fede55927590'
'mgnl:created': 2023-01-16T12:26:14.653Z
'mgnl:createdBy': 'superuser'
'mgnl:lastModified': 2023-01-16T12:26:14.653Z
'mgnl:lastModifiedBy': 'superuser'
'path': '/admin/UserAdmin/lastaccess'
'permissions': 63
'03':
'jcr:uuid': '6a704a85-4168-4b81-aa42-318bbd149783'
'mgnl:created': 2023-01-16T12:26:14.656Z
'mgnl:createdBy': 'superuser'
'mgnl:lastModified': 2023-01-16T12:26:14.656Z
'mgnl:lastModifiedBy': 'superuser'
'path': '/admin/UserAdmin/pswd'
'permissions': 63
'04':
'jcr:uuid': 'c51ea64b-763b-4dc8-9b83-37067f99db6f'
'mgnl:created': 2023-01-16T12:26:14.660Z
'mgnl:createdBy': 'superuser'
'mgnl:lastModified': 2023-01-16T12:26:14.660Z
'mgnl:lastModifiedBy': 'superuser'
'path': '/admin/UserAdmin/title'
'permissions': 63
'05':
'jcr:uuid': '2a975d6e-52b1-4877-addd-96cf3c6a072c'
'mgnl:created': 2023-01-16T12:26:14.664Z
'mgnl:createdBy': 'superuser'
'mgnl:lastModified': 2023-01-16T12:26:14.664Z
'mgnl:lastModifiedBy': 'superuser'
'path': '/admin/UserAdmin/timezone'
'permissions': 63
'06':
'jcr:uuid': '916cf921-05c0-42d5-b37e-01cd67f8051d'
'mgnl:created': 2023-01-16T12:26:14.669Z
'mgnl:createdBy': 'superuser'
'mgnl:lastModified': 2023-01-16T12:26:14.669Z
'mgnl:lastModifiedBy': 'superuser'
'path': '/admin/UserAdmin/homeScreen'
'permissions': 63
'roles':
'0': 'b4a3135a-551d-4d02-b066-50772df630a3'
'jcr:uuid': '008c3fd6-e8a5-4fe4-9945-ba97d585d7ef'

Related

Why can't I login with Google in Next.js?

When I click on the button, I see my Google accounts, and when I click on one of the accounts, I see this:
Terminal:
[next-auth][error][OAUTH_CALLBACK_ERROR]
https://next-auth.js.org/errors#oauth_callback_error expected 200 OK, got: 403 Forbidden {
error: OPError: expected 200 OK, got: 403 Forbidden
at async Client.validateIdToken (D:\my next js app\my-app\node_modules\openid-client\lib\client.js:745:49)
at async Client.callback (D:\my next js app\my-app\node_modules\openid-client\lib\client.js:488:7)
at async oAuthCallback (D:\my next js app\my-app\node_modules\next-
at async DevServer.handleRequest (D:\my next js app\my-app\node_modules\next\dist\server\base-
...
server.js:322:20) {
name: 'OAuthCallbackError',
code: undefined
},
providerId: 'google',
message: 'expected 200 OK, got: 403 Forbidden'
}
This is my [...nextauth].js file:
import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
export const authOptions = {
// Configure one or more authentication providers
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
// ...add more providers here
],
secret: process.env.JWT_SECRET,
};
export default NextAuth(authOptions);
This is my .env file:
GOOGLE_CLIENT_ID=something.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=something-
NEXTAUTH_URL=http://localhost:3000
JWT_SECRET=something
This is my button:
const { data: session } = useSession();
{session ? (
<h1>You are signed in {session.user.email}</h1>
) : (
<Button color="inherit" onClick={() => signIn('google')}>
Login
</Button>
)}
Why can't I login with Google in Next.js?
Your Secrets in the .env file is private to the server, you are actually getting undefined when using process.env.GOOGLE_CLIENT_ID.
Prefix the ENV name with NEXT_PUBLIC to make it accessible on the client:
.env
NEXT_PUBLIC_GOOGLE_CLIENT_ID=something.apps.googleusercontent.com
NEXT_PUBLIC_GOOGLE_CLIENT_SECRET=something-
NEXT_PUBLIC_NEXTAUTH_URL=http://localhost:3000
NEXT_PUBLIC_JWT_SECRET=something
Then use it in the configuration.
[...nextauth].js
import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
export const authOptions = {
providers: [
GoogleProvider({
clientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
clientSecret: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_SECRET,
}),
],
secret: process.env.NEXT_PUBLIC_JWT_SECRET,
};
export default NextAuth(authOptions);
Hope this helps.

How To Create Reset Password Using NextAuth, with credential provider

How can i create a simple reset password using next auth Credential provider with mongo db
i have user schema like this
const userSchema = new mongoose.Schema<UserSchemaType>(
{
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
img: { type: String, required: true },
isAdmin: { type: Boolean, required: true, default: false },
},
{
timestamps: true,
}
);
my next auth look like this
providers: [
CredentialsProvider({
async authorize(credentials) {
await db.connect();
const user = await User.findOne({
email: credentials.email,
});
if (user && bcryptjs.compareSync(credentials.password, user.password)) {
return {
_id: user._id,
name: user.name,
email: user.email,
image: user.img,
isAdmin: user.isAdmin,
};
}
throw new Error('Invalid email or password');
},
}),
],
});
is there a simple example for implementing reset password with the next auth
From the docs - https://next-auth.js.org/providers/credentials
The functionality provided for credentials based authentication is
intentionally limited to discourage use of passwords due to the
inherent security risks associated with them and the additional
complexity associated with supporting usernames and passwords.
Probably you can use the Email Provider and customise if you really want this feature.
https://next-auth.js.org/configuration/providers/email

Firebase siginwithcustom token returns email as UID

I am using firebase in my react native application in which i am signing into the firebase using signInWithCustomToken in which i am passing the token that is received from my server.
Once the signInWithCustomToken is successful i checked the uid of that user. Instead of getting the uid i am getting the user email id like below
_auth: Auth {_app: App, _customUrlOrRegion: undefined, namespace: "auth", _user: User, _settings: null, …}
_user: {metadata: {…}, providerData: Array(0), phoneNumber: null, photoURL: null, displayName: null, …}
displayName: (...)
email: (...)
emailVerified: (...)
isAnonymous: (...)
metadata: (...)
phoneNumber: (...)
photoURL: (...)
providerData: (...)
providerId: (...)
refreshToken: (...)
uid: "student#gmail.com"
The uid should be something like below AbHH6vQvIDS8uPXw3ZPljQnWFRp3 but i am receiving the email in uid
For custom tokens, the UID is whatever you specify in the token on your server in the call to admin.auth().createCustomToken(uid) (or equivalent for your platform). So it seems like your server-side script is passing the email address instead of a generated/obfuscated ID.

Error in event handler for "click": "ReferenceError: user is not defined"

Please help me. I have been working for days trying to fix this error and keep ending back up at the same click handler error "user not defined" I just can't figure out what it means... this is a vuejs/vuex/vuetify/firestore project. Please any help would be appreciated.
relevant code from store/index.js
updateUser({ commit, state },
payload) {
commit('setLoading', true);
commit('clearError');
firebase
.firestore()
.collection('users').doc(`users/${user.uid}`).add()
.then((data, payload) => {
const key = data.key;
let displayName = payload.name;
let address = payload.address;
let city = payload.city;
let state1 = payload.state1
let zip = payload.zip
let country = payload.country
let company = payload.company
let email = payload.email
let phoneNumber = payload.phone
commit('updateUser', {
id: key,
name: displayName,
phone: phoneNumber,
email: email,
address: address,
city: city,
state1: state1,
zip: zip,
country: country,
company: company
})
}).catch(err => {
console.log(err)
})
},
Component code...
methods: {
onUpdate() {
this.$store.dispatch("updateUser", {
email: this.email,
name: this.name,
company: this.company,
address: this.address,
city: this.city,
state1: this.state1,
zip: this.zip,
country: this.zip,
phone: this.phone,
});
},
Assuming user is a state property, ie
state: {
loading: false,
errors: [],
user: null // 👈 here
},
then your Firestore docref should be
.doc(`users/${state.user.uid}`)
Since your action performs asynchronous operations, you should consider making it composable by having it return the promise, eg
updateUser({ commit, state }, payload) {
commit('setLoading', true)
commit('clearError')
return firebase.firestore()... // 👈 note the "return" here

HTTP post request missing "onFail" callback function

I'm using the advanced-http cordova plugin. Followed all their steps in their GitHub repo.
But when I try to run my code an error pops up:
missing mandatory "onFail" callback function
Here's how my code looks like:
cordova.plugin.http.post('http://127.0.0.1:5000/api/register', {
username: this.username,
password: this.password,
firstname: this.firstname,
middlename: this.middlename,
lastname: this.lastname,
birthday: this.birthday,
age: this.age,
contact: this.contact,
address: this.address,
prisoner: this.prisoner
}, response => {
try {
response.data = JSON.parse(response.data);
// prints test
console.log(response.data.message);
} catch(e) {
console.error('JSON parsing error');
}
}, response => {
// prints 403
console.log(response.status);
//prints Permission denied
console.log(response.error);
});
What am I missing here? Please help.
you are missing headers parameter in your call. According to docs linked in the question:
Takes a URL, data, and headers.
cordova.plugin.http.post('http://127.0.0.1:5000/api/register', {
username: this.username,
password: this.password,
firstname: this.firstname,
middlename: this.middlename,
lastname: this.lastname,
birthday: this.birthday,
age: this.age,
contact: this.contact,
address: this.address,
prisoner: this.prisoner
},
{ //your_headers_here
},
response=> {//success callback
},
response=> {//error callback
});

Resources