Skip to content

Commit

Permalink
Change placement of constant
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranahmedse committed Apr 10, 2023
1 parent 3072e42 commit 44ce3a3
Show file tree
Hide file tree
Showing 17 changed files with 13 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/components/AuthenticationFlow/EmailLoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Cookies from 'js-cookie';
import type { FunctionComponent } from 'preact';
import { useState } from 'preact/hooks';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
import Spinner from '../Spinner';
import { httpPost } from '../../lib/http';
import {TOKEN_COOKIE_NAME} from "../../lib/jwt";

const EmailLoginForm: FunctionComponent<{}> = () => {
const [email, setEmail] = useState<string>('');
Expand Down
2 changes: 1 addition & 1 deletion src/components/AuthenticationFlow/GitHubButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useEffect, useState } from 'preact/hooks';

import GitHubIcon from '../../icons/github.svg';
import SpinnerIcon from '../../icons/spinner.svg';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
import Cookies from 'js-cookie';
import {TOKEN_COOKIE_NAME} from "../../lib/jwt";

type GitHubButtonProps = {};

Expand Down
2 changes: 1 addition & 1 deletion src/components/AuthenticationFlow/GoogleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'preact/hooks';
import Cookies from 'js-cookie';
import GoogleIcon from '../../icons/google.svg';
import SpinnerIcon from '../../icons/spinner.svg';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
import {TOKEN_COOKIE_NAME} from "../../lib/jwt";

type GoogleButtonProps = {};

Expand Down
2 changes: 1 addition & 1 deletion src/components/AuthenticationFlow/ResetPasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'preact/hooks';
import Spinner from '../Spinner';
import { httpPost } from '../../lib/http';
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
import {TOKEN_COOKIE_NAME} from "../../lib/jwt";

export default function ResetPasswordForm() {
const [code, setCode] = useState('');
Expand Down
2 changes: 1 addition & 1 deletion src/components/AuthenticationFlow/TriggerVerifyAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ErrorIcon from '../../icons/error.svg';

import { useEffect, useState } from 'preact/hooks';
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
import {TOKEN_COOKIE_NAME} from "../../lib/jwt";

export function TriggerVerifyAccount() {
const [isLoading, setIsLoading] = useState(true);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Authenticator/authenticator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
import {TOKEN_COOKIE_NAME} from "../../lib/jwt";

function easeInElement(el: Element) {
el.classList.add('opacity-0', 'transition-opacity', 'duration-300');
Expand Down
5 changes: 0 additions & 5 deletions src/components/Navigation/Navigation.astro
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ import AccountDropdown from './AccountDropdown.astro';
</li>

<!-- Links for logged in users -->
<li data-auth-required class='hidden'>
<a href='/profile' class='text-xl hover:text-blue-300 md:text-lg'>
Profile
</a>
</li>
<li data-auth-required class='hidden'>
<a
href='/settings/profile'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Navigation/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
import { handleAuthRequired } from '../Authenticator/authenticator';
import {TOKEN_COOKIE_NAME} from "../../lib/jwt";

function logout() {
Cookies.remove(TOKEN_COOKIE_NAME);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Setting/ChangePasswordForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useState } from 'preact/hooks';
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
import Spinner from '../Spinner';
import {TOKEN_COOKIE_NAME} from "../../lib/jwt";

export default function ChangePasswordForm() {
const [authProvider, setAuthProvider] = useState<
Expand Down
2 changes: 1 addition & 1 deletion src/components/Setting/UpdateProfileForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useState } from 'preact/hooks';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
import Cookies from 'js-cookie';
import Spinner from '../Spinner';
import {TOKEN_COOKIE_NAME} from "../../lib/jwt";

export default function UpdateProfileForm() {
const [name, setName] = useState('');
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/use-auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect, useState } from 'preact/hooks';
import { TokenPayload, decodeToken } from '../lib/jwt';
import {TokenPayload, decodeToken, TOKEN_COOKIE_NAME} from '../lib/jwt';
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../lib/constants';

export const useAuth = () => {
const [user, setUser] = useState<TokenPayload | null>(null);
Expand Down
8 changes: 0 additions & 8 deletions src/lib/constants.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from './constants';
import {TOKEN_COOKIE_NAME} from "./jwt";

type AppResponse = Record<string, any>;
type FetchError = {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as jose from 'jose';

export const TOKEN_COOKIE_NAME = '__roadmapsh_jt__';

export type TokenPayload = {
id: string;
email: string;
Expand Down
19 changes: 0 additions & 19 deletions src/pages/profile/index.astro

This file was deleted.

10 changes: 0 additions & 10 deletions src/pages/settings/change-password.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,3 @@ import SettingLayout from '../../layouts/SettingLayout.astro';
<ChangePasswordForm client:load />
</SettingSidebar>
</SettingLayout>

<script>
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
const token = Cookies.get(TOKEN_COOKIE_NAME);

if (!token) {
window.location.href = '/';
}
</script>
10 changes: 0 additions & 10 deletions src/pages/settings/profile.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,3 @@ import SettingLayout from '../../layouts/SettingLayout.astro';
<UpdateProfileForm client:load />
</SettingSidebar>
</SettingLayout>

<script>
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../../lib/constants';
const token = Cookies.get(TOKEN_COOKIE_NAME);

if (!token) {
window.location.href = '/';
}
</script>

0 comments on commit 44ce3a3

Please sign in to comment.