Replies: 5 comments
-
Guys. It is important. We need to make it possible to verify Google on the backend side, without this the google strategy is useless. |
Beta Was this translation helpful? Give feedback.
-
The same thing happend to me, so this is what I did I created an auth plugin called extendedAuth.client.js, in there I would do an api request using the user's email and name as the payload (first I had to configure google's console api in order to get the user email as well as his profile) Then in the database, I would do a simple check: if the email doesn't exists in my User's table, then I create a new record with that email, with some fake password, and if the email is there, then I would do nothing |
Beta Was this translation helpful? Give feedback.
-
@dajpes , great idea, i'm trying to do the same. can you please share some code for that plugin? |
Beta Was this translation helpful? Give feedback.
-
@RonAlmog This how I have it on nuxt: nuxt.config.js: auth: {
...
plugins: ['~/plugins/extendAuth.client.js'], // the file is .client.js because I only want it to run on the client side
} extendAuth.client.js export default async function ({ $auth, $axios }) {
if (!$auth.loggedIn) return
$auth.$state.loggedInFromServer = false
if ($auth.user.uid !== undefined) return
//Perform a login if strategy is not local
await $axios
.$post('/user', {
email: $auth.$state.user.email,
full_name: $auth.$state.user.name,
})
.then((e) => {
$auth.$state.loggedInFromServer = true
$auth.setUserToken(e.token)
})
.catch((e) => {
console.log('Error extend user auth: ', e)
})
} Then on my BE using adonisJs //If user doesn't exists, then I create a new record for that email and then generate a token and send it back to the FE, and if the user exists then I just create the token and send it back to the FE:
public async checkOrCreate({ auth, request, response }: HttpContextContract) {
const { email, full_name } = request.all();
let getUser = await User.findBy("email", email); // This is where I search for the user
if (getUser === null) {
getUser = await User.create({
email: email,
password: crypto.randomBytes(8).toString("hex"),
fullName: full_name,
});
const { token } = await auth.use("api").generate(getUser, {
expiresIn: '120mins'
})
return response.ok({ message: "User Created", token: token });
}
const { token } = await auth.use("api").generate(getUser, {
expiresIn: '120mins'
})
return response.ok({ message: "User loggedIn", token: token });
} |
Beta Was this translation helpful? Give feedback.
-
Thank you! |
Beta Was this translation helpful? Give feedback.
-
Hello everyone,
I am trying to implement the
google strategy
but now when I log in I would like to save the user's information in my mongodb database.I really don't know how to implement it because I'm checking the documentation but I can't find something similar. Please help me
Beta Was this translation helpful? Give feedback.
All reactions