chore: Use currentUser from authentication
This commit is contained in:
@@ -1,18 +1,14 @@
|
|||||||
import { GraphQLNonNull, GraphQLInt } from 'graphql';
|
import { GraphQLNonNull, GraphQLInt } from 'graphql';
|
||||||
import Credential from '../../models/credential';
|
import Credential from '../../models/credential';
|
||||||
import authLinkType from '../types/auth-link';
|
import authLinkType from '../types/auth-link';
|
||||||
import User from '../../models/user';
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
credentialId: number,
|
credentialId: number,
|
||||||
}
|
}
|
||||||
const createAuthLinkResolver = async (params: Params) => {
|
const createAuthLinkResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
const user = await User.query().findOne({
|
|
||||||
email: 'user@automatisch.com'
|
|
||||||
})
|
|
||||||
|
|
||||||
const credential = await Credential.query().findOne({
|
const credential = await Credential.query().findOne({
|
||||||
user_id: user.id,
|
user_id: req.currentUser.id,
|
||||||
id: params.credentialId
|
id: params.credentialId
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -29,7 +25,7 @@ const createAuthLink = {
|
|||||||
args: {
|
args: {
|
||||||
credentialId: { type: GraphQLNonNull(GraphQLInt) },
|
credentialId: { type: GraphQLNonNull(GraphQLInt) },
|
||||||
},
|
},
|
||||||
resolve: (_: any, params: Params) => createAuthLinkResolver(params)
|
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createAuthLinkResolver(params, req)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createAuthLink;
|
export default createAuthLink;
|
||||||
|
@@ -1,24 +1,20 @@
|
|||||||
import { GraphQLString, GraphQLNonNull, GraphQLObjectType, GraphQLCompositeType } from 'graphql';
|
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
import Credential from '../../models/credential';
|
import Credential from '../../models/credential';
|
||||||
import credentialType from '../types/credential';
|
import credentialType from '../types/credential';
|
||||||
import twitterCredentialInputType from '../types/twitter-credential-input';
|
import twitterCredentialInputType from '../types/twitter-credential-input';
|
||||||
import User from '../../models/user';
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
key: string,
|
key: string,
|
||||||
displayName: string,
|
displayName: string,
|
||||||
data: object
|
data: object
|
||||||
}
|
}
|
||||||
const createCredentialResolver = async (params: Params) => {
|
const createCredentialResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
const user = await User.query().findOne({
|
|
||||||
email: 'user@automatisch.com'
|
|
||||||
})
|
|
||||||
|
|
||||||
const credential = await Credential.query().insert({
|
const credential = await Credential.query().insert({
|
||||||
displayName: params.displayName,
|
displayName: params.displayName,
|
||||||
key: params.key,
|
key: params.key,
|
||||||
data: params.data,
|
data: params.data,
|
||||||
userId: user.id
|
userId: req.currentUser.id
|
||||||
});
|
});
|
||||||
|
|
||||||
return credential;
|
return credential;
|
||||||
@@ -31,7 +27,7 @@ const createCredential = {
|
|||||||
displayName: { type: GraphQLNonNull(GraphQLString) },
|
displayName: { type: GraphQLNonNull(GraphQLString) },
|
||||||
data: { type: GraphQLNonNull(twitterCredentialInputType) }
|
data: { type: GraphQLNonNull(twitterCredentialInputType) }
|
||||||
},
|
},
|
||||||
resolve: (_: any, params: Params) => createCredentialResolver(params)
|
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createCredentialResolver(params, req)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createCredential;
|
export default createCredential;
|
||||||
|
@@ -1,10 +1,6 @@
|
|||||||
import { Request, Response, NextFunction } from 'express';
|
import { Request, Response, NextFunction } from 'express';
|
||||||
import User from '../models/user';
|
import User from '../models/user';
|
||||||
import UserType from '../types/user';
|
import RequestWithCurrentUser from '../types/express/request-with-current-user';
|
||||||
|
|
||||||
interface RequestWithCurrentUser extends Request {
|
|
||||||
currentUser: UserType
|
|
||||||
}
|
|
||||||
|
|
||||||
const authentication = async (req: RequestWithCurrentUser, _res: Response, next: NextFunction) => {
|
const authentication = async (req: RequestWithCurrentUser, _res: Response, next: NextFunction) => {
|
||||||
// We set authentication to use the sample user we created temporarily.
|
// We set authentication to use the sample user we created temporarily.
|
||||||
|
8
packages/backend/src/types/express/request-with-current-user.d.ts
vendored
Normal file
8
packages/backend/src/types/express/request-with-current-user.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { Request } from 'express';
|
||||||
|
import User from '../user';
|
||||||
|
|
||||||
|
interface RequestWithCurrentUser extends Request {
|
||||||
|
currentUser: User
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RequestWithCurrentUser;
|
Reference in New Issue
Block a user