-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b775d65
commit 6700d02
Showing
8 changed files
with
130 additions
and
16 deletions.
There are no files selected for viewing
This file was deleted.
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,38 @@ | ||
import { getRepository } from 'typeorm'; | ||
import { User } from '../entities/user.auth'; | ||
|
||
async function findUserAccountIdProvider(accountId: string, provider: string): Promise<User | undefined> { | ||
try { | ||
const userRepository = getRepository(User); | ||
|
||
const user = await userRepository.findOne({ | ||
where: { | ||
accountId: accountId, | ||
provider: provider, | ||
}, | ||
}); | ||
|
||
if (user === null) { | ||
return undefined; | ||
} | ||
|
||
return user as User; | ||
} catch (error) { | ||
console.error('Error finding user:', error); | ||
return undefined; | ||
} | ||
} | ||
const accountId = 'your_account_id'; | ||
const provider = 'facebook'; | ||
|
||
findUserAccountIdProvider(accountId, provider) | ||
.then((user) => { | ||
if (user) { | ||
console.log('User found:', user); | ||
} else { | ||
console.log('User not found'); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error); | ||
}); |
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,22 @@ | ||
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from 'typeorm'; | ||
|
||
@Entity() | ||
export class User extends BaseEntity { | ||
@PrimaryGeneratedColumn('uuid') | ||
id: string | undefined; | ||
|
||
@Column({ type: 'text', nullable: true, unique: true }) | ||
email: string | undefined; | ||
|
||
@Column({ type: 'text', nullable: true }) | ||
accountId: string | undefined; | ||
|
||
@Column({ type: 'text', nullable: true }) | ||
name!: string; | ||
|
||
@Column({ type: 'text', nullable: true }) | ||
photoURL: string | undefined; | ||
|
||
@Column({ type: 'text', nullable: true }) | ||
provider: string | undefined; | ||
} |
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,21 @@ | ||
import passport from 'passport'; | ||
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'; | ||
|
||
export function passportConfig() { | ||
const clientID = process.env.GOOGLE_CLIENT_ID; | ||
const clientSecret = process.env.GOOGLE_CLIENT_SECRET; | ||
|
||
if (!clientID || !clientSecret) { | ||
throw new Error('Google client ID or client secret is missing.'); | ||
} | ||
|
||
passport.use(new GoogleStrategy({ | ||
clientID, | ||
clientSecret, | ||
callbackURL: "/auth/google/callback" | ||
}, | ||
(accessToken, refreshToken, profile, done) => { | ||
done(null, profile); | ||
} | ||
)); | ||
} |