mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-06-07 08:03:56 +02:00
feat: github connect uses user id instead of username
This commit is contained in:
@@ -68,6 +68,9 @@ async function connect(db) {
|
|||||||
accessTokens: {
|
accessTokens: {
|
||||||
github: r.accessToken,
|
github: r.accessToken,
|
||||||
},
|
},
|
||||||
|
externalIDs: {
|
||||||
|
github: r.profile.id,
|
||||||
|
},
|
||||||
username: r.username,
|
username: r.username,
|
||||||
emails: r.profile.emails.map((email) => {
|
emails: r.profile.emails.map((email) => {
|
||||||
return { email: email.value, default: false };
|
return { email: email.value, default: false };
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ const UserSchema = new Schema({
|
|||||||
accessTokens: {
|
accessTokens: {
|
||||||
github: { type: String },
|
github: { type: String },
|
||||||
},
|
},
|
||||||
|
externalIDs: {
|
||||||
|
github: { type: String },
|
||||||
|
},
|
||||||
username: {
|
username: {
|
||||||
type: String,
|
type: String,
|
||||||
index: { unique: true },
|
index: { unique: true },
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ export interface IUser {
|
|||||||
accessTokens: {
|
accessTokens: {
|
||||||
github: string;
|
github: string;
|
||||||
};
|
};
|
||||||
|
externalIDs: {
|
||||||
|
github: string;
|
||||||
|
};
|
||||||
username: string;
|
username: string;
|
||||||
emails: {
|
emails: {
|
||||||
email: string;
|
email: string;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import * as express from "express";
|
|||||||
|
|
||||||
import config from "../../config";
|
import config from "../../config";
|
||||||
import UserModel from "../database/users/users.model";
|
import UserModel from "../database/users/users.model";
|
||||||
|
import { IUserDocument } from "../database/users/users.types";
|
||||||
|
|
||||||
const RedisStore = connectRedis(session);
|
const RedisStore = connectRedis(session);
|
||||||
|
|
||||||
@@ -28,9 +29,9 @@ const verify = async (
|
|||||||
profile: Profile,
|
profile: Profile,
|
||||||
done: OAuth2Strategy.VerifyCallback
|
done: OAuth2Strategy.VerifyCallback
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
let user;
|
let user: IUserDocument;
|
||||||
try {
|
try {
|
||||||
user = await UserModel.findOne({ username: profile.username });
|
user = await UserModel.findOne({ "externalIDs.github": profile.id });
|
||||||
const email = profile.emails ? profile.emails[0]?.value : null;
|
const email = profile.emails ? profile.emails[0]?.value : null;
|
||||||
const photo = profile.photos ? profile.photos[0]?.value : null;
|
const photo = profile.photos ? profile.photos[0]?.value : null;
|
||||||
if (user) {
|
if (user) {
|
||||||
|
|||||||
Reference in New Issue
Block a user