Skip to content

Commit 8a3400f

Browse files
committed
move auth to separate utils folder
1 parent 64d68b9 commit 8a3400f

File tree

9 files changed

+28
-34
lines changed

9 files changed

+28
-34
lines changed

packages/gatsby-theme/src/Apollo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { HttpLink } from 'apollo-link-http';
44
import { InMemoryCache } from 'apollo-cache-inmemory';
55
import fetch from 'isomorphic-fetch';
66
import config from '../config';
7-
import { getAuthToken } from './utils/auth';
7+
import { getAuthToken } from './utils/auth/auth';
88

99
const authLink = setContext((_, { headers }) => {
1010
// get the authentication token from local storage if it exists

packages/gatsby-theme/src/components/Account.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React from 'react';
22
import { Text, Image, Flex } from './shared/base';
33
import { Link } from 'gatsby';
44
import CustomButton from './CustomButton';
5-
import { loginUser } from '../utils/auth';
6-
import WithCurrentUser from '../utils/WithCurrentUser';
5+
import { loginUser } from '../utils/auth/auth';
6+
import WithCurrentUser from '../utils/auth/WithCurrentUser';
77
import { CenteredLoader } from '../components/Loader';
88

99
const Account = () => {

packages/gatsby-theme/src/components/Upvote.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
22
import { Heading, Flex } from './shared/base';
33
import CustomButton from './CustomButton';
4-
import { loginUser } from '../utils/auth';
5-
import WithCurrentUser from '../utils/WithCurrentUser';
4+
import { loginUser } from '../utils/auth/auth';
5+
import WithCurrentUser from '../utils/auth/WithCurrentUser';
66

77
const Upvote = () => {
88
return (

packages/gatsby-theme/src/components/queries/userQueries.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/gatsby-theme/src/pages/profile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from 'react';
22
import Layout from '../components/layout';
33
import { Text, Image, Flex } from '../components/shared/base';
4-
import { logoutUser } from '../utils/auth';
4+
import { logoutUser } from '../utils/auth/auth';
55
import { navigate } from 'gatsby';
6-
import WithCurrentUser from '../utils/WithCurrentUser';
6+
import WithCurrentUser from '../utils/auth/WithCurrentUser';
77
import { CenteredLoader } from '../components/Loader';
88

99
const Profile = () => {

packages/gatsby-theme/src/pages/signup.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import { navigate } from 'gatsby';
44
import { CenteredLoader } from '../components/Loader';
55
import { Flex, Text, Box } from '../components/shared/base';
66
import CustomButton from '../components/CustomButton';
7-
import { loginUser } from '../utils/auth';
8-
<<<<<<< HEAD
9-
import { CURRENT_USER } from '../components/queries/userQueries';
10-
import { optionalChaining } from '../utils/helpers';
11-
=======
12-
import WithCurrentUser from '../utils/WithCurrentUser';
13-
>>>>>>> create WithCurrentUser component
7+
import WithCurrentUser from '../utils/auth/WithCurrentUser';
8+
import { loginUser } from '../utils/auth/auth';
149

1510
const Signup = () => {
1611
return (

packages/gatsby-theme/src/utils/WithCurrentUser.js renamed to packages/gatsby-theme/src/utils/auth/WithCurrentUser.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import { Query } from 'react-apollo';
3-
import { CURRENT_USER } from '../components/queries/userQueries';
4-
import { optionalChaining } from './helpers';
3+
import { optionalChaining } from '../helpers';
4+
import gql from 'graphql-tag';
55

66
const WithCurrentUser = ({ children }) => {
77
return (
@@ -20,4 +20,18 @@ const WithCurrentUser = ({ children }) => {
2020
);
2121
};
2222

23+
export const CURRENT_USER = gql`
24+
query currentUser {
25+
viewer {
26+
id
27+
user {
28+
id
29+
name
30+
avatarUrl
31+
githubHandle
32+
}
33+
}
34+
}
35+
`;
36+
2337
export default WithCurrentUser;

packages/gatsby-theme/src/utils/auth.ts renamed to packages/gatsby-theme/src/utils/auth/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import gql from 'graphql-tag';
2-
import { client } from '../Apollo';
3-
import config from '../../config';
2+
import { client } from '../../Apollo';
3+
import config from '../../../config';
44

55
const TOKEN_KEY = 'token';
66

packages/gatsby-theme/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"baseUrl": "."
2222
},
2323
"exclude": ["node_modules"],
24-
"include": ["./src/**/*.tsx", "./src/**/*.ts", "./images.d.ts"]
24+
"include": ["./src/**/*.tsx", "./src/**/*.ts", "./images.d.ts", "src/utils/WithCurrentUser.js"]
2525
}

0 commit comments

Comments
 (0)