curl --request POST \
--url https://api.example.com/api/auth/google \
--header 'Content-Type: application/json' \
--data '
{
"token": "<string>"
}
'{
"200": {},
"400": {},
"401": {},
"success": true,
"data": {
"user": {
"id": 123,
"email": "<string>",
"nombre": "<string>",
"apellido": "<string>",
"googleId": "<string>",
"role": "<string>"
},
"token": "<string>"
}
}Authenticate a user with Google OAuth
curl --request POST \
--url https://api.example.com/api/auth/google \
--header 'Content-Type: application/json' \
--data '
{
"token": "<string>"
}
'{
"200": {},
"400": {},
"401": {},
"success": true,
"data": {
"user": {
"id": 123,
"email": "<string>",
"nombre": "<string>",
"apellido": "<string>",
"googleId": "<string>",
"role": "<string>"
},
"token": "<string>"
}
}POST /api/auth/google
Show data properties
{
"success": false,
"error": "Error autenticando con Google"
}
{
"success": false,
"error": "Falta el token de Google"
}
curl -X POST https://api.pcfix.com/api/auth/google \
-H "Content-Type: application/json" \
-d '{
"token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjE4MmU0M..."
}'
// After obtaining the Google ID token from Google Sign-In
const response = await fetch('https://api.pcfix.com/api/auth/google', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
token: googleIdToken
})
});
const data = await response.json();
console.log(data);
import requests
# After obtaining the Google ID token from Google Sign-In
response = requests.post(
'https://api.pcfix.com/api/auth/google',
json={
'token': google_id_token
}
)
data = response.json()
print(data)
{
"success": true,
"data": {
"user": {
"id": 789,
"email": "[email protected]",
"nombre": "Carlos",
"apellido": "Rodríguez",
"googleId": "117234567890123456789",
"role": "USER"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
password field is set to an empty string (password login is disabled)googleId yet, it will be added to their profile// Initialize Google Sign-In
google.accounts.id.initialize({
client_id: 'YOUR_GOOGLE_CLIENT_ID',
callback: handleCredentialResponse
});
// Handle the credential response
async function handleCredentialResponse(response) {
const googleToken = response.credential;
// Send to your API
const result = await fetch('https://api.pcfix.com/api/auth/google', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token: googleToken })
});
const data = await result.json();
// Store the JWT token for authenticated requests
localStorage.setItem('authToken', data.data.token);
}
password field and cannot use email/password login unless they set a password separately