I just want to know how to save playerId or userDevice in database using flutter. How to get the playerId for user device in flutter , user may have 2 phones so there should be deviceid save for reciving notification in both phone
This is my api controller:
module.exports.deviceTokenController = asyncHandler(async(req,res)=>{
const { error } = validationCreateDeviceToken(req.body);
if(error){
return res.status(400).json({message : error.details[0].message});
}
const { deviceToken , playerId} = req.body;
const userId = req.user.id;
const existingTokens = await DeviceToken.find({ userId });
const existingToken = existingTokens.find(token => token.playerId === playerId);
if(existingToken){
existingToken.deviceToken = deviceToken;
await existingToken.save();
return res.status(200).json({message : "Device token updated."});
}else{
const newDeviceToken = new DeviceToken({
deviceToken,
playerId,
userId
});
await newDeviceToken.save();
return res.status(201).json({message : "New device token created."});
}
});
Just want to know how to get playerId in flutter, what is the code or library to get it