google account
parent
350592548f
commit
2daf1042ce
|
@ -86,6 +86,8 @@ export async function GetCalendarSettings(req: Request, res: Response) {
|
|||
"calendar_max_future_booking_days",
|
||||
"calendar_min_earliest_booking_time",
|
||||
"calendar_using_primary_calendar",
|
||||
"google_account_name",
|
||||
"google_account_picture",
|
||||
],
|
||||
});
|
||||
|
||||
|
@ -98,6 +100,8 @@ export async function GetCalendarSettings(req: Request, res: Response) {
|
|||
calendar_max_future_booking_days: user.calendar_max_future_booking_days,
|
||||
calendar_min_earliest_booking_time:
|
||||
user.calendar_min_earliest_booking_time,
|
||||
google_account_name: user.google_account_name,
|
||||
google_account_picture: user.google_account_picture,
|
||||
};
|
||||
|
||||
const store = await Store.findOne({
|
||||
|
|
|
@ -14,6 +14,8 @@ interface UserAttributes {
|
|||
calendar_using_primary_calendar?: boolean;
|
||||
language: string;
|
||||
state: number; // like active, deleted, etc
|
||||
google_account_name?: string;
|
||||
google_account_picture?: string;
|
||||
analytics_enabled: boolean;
|
||||
}
|
||||
|
||||
|
@ -30,6 +32,8 @@ class User extends Model<UserAttributes> implements UserAttributes {
|
|||
declare language: string;
|
||||
declare state: number;
|
||||
declare analytics_enabled: boolean;
|
||||
declare google_account_name: string;
|
||||
declare google_account_picture: string;
|
||||
declare created_at: Date;
|
||||
}
|
||||
|
||||
|
@ -85,6 +89,14 @@ User.init(
|
|||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
},
|
||||
google_account_name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
google_account_picture: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: "users",
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
PASSPORT_FAILURE_REDIRECT_URL,
|
||||
PASSPORT_SUCCESS_REDIRECT_URL,
|
||||
} from "../utils/constants";
|
||||
import User from "../models/user";
|
||||
|
||||
router.get(
|
||||
"/auth/google",
|
||||
|
@ -31,13 +32,7 @@ router.get(
|
|||
failureRedirect: PASSPORT_FAILURE_REDIRECT_URL,
|
||||
}),
|
||||
function (req, res) {
|
||||
// Successful authentication, redirect home.
|
||||
const accessToken = (req.user as Request & { accessToken?: string })
|
||||
.accessToken;
|
||||
const refreshToken = (req.user as Request & { refreshToken?: string })
|
||||
.refreshToken;
|
||||
const sub = (req.user as Request & { profile?: any }).profile._json.sub; // google user id
|
||||
|
||||
// Successful authentication, redirect home
|
||||
const sessionId = req.cookies["session"];
|
||||
|
||||
if (!sessionId) {
|
||||
|
@ -46,6 +41,17 @@ router.get(
|
|||
return;
|
||||
}
|
||||
|
||||
const accessToken = (req.user as Request & { accessToken?: string })
|
||||
.accessToken;
|
||||
const refreshToken = (req.user as Request & { refreshToken?: string })
|
||||
.refreshToken;
|
||||
const sub = (req.user as Request & { profile?: any }).profile._json.sub; // google user id
|
||||
|
||||
const googleAccountName = (req.user as Request & { profile?: any }).profile
|
||||
._json.name;
|
||||
const googleAccountPicture = (req.user as Request & { profile?: any })
|
||||
.profile._json.picture;
|
||||
|
||||
Session.findOne({
|
||||
where: {
|
||||
session_id: sessionId,
|
||||
|
@ -74,6 +80,27 @@ router.get(
|
|||
logger.info("err %s", err);
|
||||
});
|
||||
|
||||
User.findOne({
|
||||
where: {
|
||||
user_id: userSession.user_id,
|
||||
},
|
||||
})
|
||||
.then((user) => {
|
||||
if (!user) {
|
||||
logger.error("user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
user.google_account_name = googleAccountName;
|
||||
user.google_account_picture = googleAccountPicture;
|
||||
|
||||
user.save().catch((err) => logger.error(err));
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(err);
|
||||
res.redirect(PASSPORT_FAILURE_REDIRECT_URL);
|
||||
});
|
||||
|
||||
res.redirect(PASSPORT_SUCCESS_REDIRECT_URL);
|
||||
})
|
||||
.catch((err) => {
|
||||
|
|
Loading…
Reference in New Issue