Skip to content

Commit 50da572

Browse files
committed
feat(auth google): add support for set timezone when create user
1 parent 1ad39c4 commit 50da572

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/config/passport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ const jwtLogin = new JwtStrategy(
8787
const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID as string;
8888
const GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET as string;
8989

90-
9190
const googleStrategy = new GoogleStrategy(
9291
{
9392
clientID: GOOGLE_CLIENT_ID,
@@ -146,6 +145,7 @@ const googleStrategy = new GoogleStrategy(
146145
firstName: profile.name?.familyName || "Non renseigné",
147146
lastName: profile.name?.givenName || "Non renseigné",
148147
},
148+
timezone: stateData?.timezone,
149149
});
150150

151151
// Pass both user and state data to the callback

src/controllers/auth.controller.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,22 @@ async function loginWithGoogle(
120120
) {
121121
try {
122122
const redirectUrl = (req.query.redirectUrl || "") as string;
123+
const timezone = (req.query.timezone || "") as string;
124+
125+
console.log(timezone);
123126

124127
const stateObject = {
125-
data: {} as { redirectUrl?: string },
128+
data: {} as { redirectUrl?: string; timezone?: string },
126129
};
127130

128131
if (["profile"].includes(redirectUrl)) {
129132
stateObject.data.redirectUrl = redirectUrl;
130133
}
131134

135+
if (timezone) {
136+
stateObject.data.timezone = timezone;
137+
}
138+
132139
// Encode state as base64url (URL-safe)
133140
const stateJson = JSON.stringify(stateObject);
134141
const state = Buffer.from(stateJson).toString("base64url");

src/services/users.services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const findOrCreateUser = async (userData: Partial<IUser>) => {
3333
password: null,
3434
googleId: userData.googleId,
3535
profile: userData.profile || {},
36+
timezone: userData.timezone,
3637
isVerified: true,
3738
});
3839

0 commit comments

Comments
 (0)