-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Roger13579/features/U003
feat: add google oauth function, optimize route structure
- Loading branch information
Showing
15 changed files
with
381 additions
and
63 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export class GoogleProfileDto { | ||
private readonly id: string; | ||
private readonly name: string; | ||
private readonly email: string; | ||
private readonly picture: string; | ||
private readonly emailVerified: boolean; | ||
|
||
get getId(): string { | ||
return this.id; | ||
} | ||
get getName(): string { | ||
return this.name; | ||
} | ||
get getEmail(): string { | ||
return this.email; | ||
} | ||
get getPicture(): string { | ||
return this.picture; | ||
} | ||
get getEmailVerified(): boolean { | ||
return this.emailVerified; | ||
} | ||
|
||
constructor(googleUser: any) { | ||
this.id = googleUser._json.sub; | ||
this.name = googleUser._json.name; | ||
this.email = googleUser._json.email; | ||
this.picture = googleUser._json.picture; | ||
this.emailVerified = googleUser._json.email_verified; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
import { Request } from 'express'; | ||
|
||
export class ResetPwdDto { | ||
private readonly id: string; | ||
private readonly oldPwd: string; | ||
private readonly pwd: string; | ||
private readonly confirmPwd: string; | ||
private readonly id: string; | ||
private readonly oldPwd: string; | ||
private readonly pwd: string; | ||
private readonly confirmPwd: string; | ||
|
||
get getId(): string { | ||
return this.id; | ||
} | ||
get getOldPwd(): string { | ||
return this.oldPwd; | ||
} | ||
get getPwd(): string { | ||
return this.pwd; | ||
} | ||
get getConfirmPwd(): string { | ||
return this.confirmPwd; | ||
} | ||
get getId(): string { | ||
return this.id; | ||
} | ||
get getOldPwd(): string { | ||
return this.oldPwd; | ||
} | ||
get getPwd(): string { | ||
return this.pwd; | ||
} | ||
get getConfirmPwd(): string { | ||
return this.confirmPwd; | ||
} | ||
|
||
constructor(req: Request) { | ||
this.id = (req.user as any).id; | ||
const { oldPwd, pwd, confirmPwd } = req.body; | ||
this.oldPwd = oldPwd; | ||
this.pwd = pwd; | ||
this.confirmPwd = confirmPwd; | ||
} | ||
constructor(req: Request) { | ||
this.id = (req.user as any).id; | ||
const { oldPwd, pwd, confirmPwd } = req.body; | ||
this.oldPwd = oldPwd; | ||
this.pwd = pwd; | ||
this.confirmPwd = confirmPwd; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import passport from 'passport'; | ||
import { NextFunction, Response, Request } from 'express'; | ||
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'; | ||
|
||
export const PassportInit = async ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
passport.use( | ||
new GoogleStrategy( | ||
{ | ||
clientID: process.env.GOOGLE_OAUTH_CLIENT_ID as string, | ||
clientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET as string, | ||
callbackURL: process.env.GOOGLE_OAUTH_CALLBACK_URL as string, | ||
}, | ||
( | ||
accessToken: any, | ||
refreshToken: any, | ||
profile: any, | ||
cb: (arg0: null, arg1: any) => any, | ||
) => { | ||
return cb(null, profile); | ||
}, | ||
), | ||
); | ||
return next(); | ||
}; |
Oops, something went wrong.