Fix ENV usage
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
API_URL=https://api.dev.sik.party/api
|
NEXT_PUBLIC_API_URL=https://api.dev.sik.party/api
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const url = `${process.env.API_URL}/contacts`;
|
const url = `${process.env.NEXT_PUBLIC_API_URL}/contacts`;
|
||||||
const committeeUrl = `${process.env.API_URL}/committees`;
|
const committeeUrl = `${process.env.NEXT_PUBLIC_API_URL}/committees`;
|
||||||
|
|
||||||
export interface Committee {
|
export interface Committee {
|
||||||
name_fi: string;
|
name_fi: string;
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import { getAuthHeader } from "@utils/auth";
|
|||||||
import { Tag } from "./Tag";
|
import { Tag } from "./Tag";
|
||||||
import qs from "query-string";
|
import qs from "query-string";
|
||||||
import { SignupForm } from "./SignupForm";
|
import { SignupForm } from "./SignupForm";
|
||||||
const url = `${process.env.API_URL}/events/`;
|
const url = `${process.env.NEXT_PUBLIC_API_URL}/events/`;
|
||||||
|
|
||||||
export interface Event {
|
export interface Event {
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ import axios from "axios";
|
|||||||
import { getAuthHeader } from "@utils/auth";
|
import { getAuthHeader } from "@utils/auth";
|
||||||
import { Tag } from "./Tag";
|
import { Tag } from "./Tag";
|
||||||
|
|
||||||
const url = `${process.env.API_URL}/feed/`;
|
const url = `${process.env.NEXT_PUBLIC_API_URL}/feed/`;
|
||||||
|
|
||||||
export interface Post {
|
export interface Post {
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import qs from "query-string";
|
import qs from "query-string";
|
||||||
import { getAuthHeader } from "@utils/auth";
|
import { getAuthHeader } from "@utils/auth";
|
||||||
const url = `${process.env.API_URL}/jobads/`;
|
const url = `${process.env.NEXT_PUBLIC_API_URL}/jobads/`;
|
||||||
|
|
||||||
export interface JobAd {
|
export interface JobAd {
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { getAuthHeader } from "@utils/auth";
|
import { getAuthHeader } from "@utils/auth";
|
||||||
const url = `${process.env.API_URL}/signup/`;
|
const url = `${process.env.NEXT_PUBLIC_API_URL}/signup/`;
|
||||||
|
|
||||||
export interface Signup {
|
export interface Signup {
|
||||||
id?: number;
|
id?: number;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { getAuthHeader } from "@utils/auth";
|
import { getAuthHeader } from "@utils/auth";
|
||||||
const url = `${process.env.API_URL}/signupForm/`;
|
const url = `${process.env.NEXT_PUBLIC_API_URL}/signupForm/`;
|
||||||
import { Question } from "@components/Widgets/SignupQuestionsWidget";
|
import { Question } from "@components/Widgets/SignupQuestionsWidget";
|
||||||
import { Signup } from "./Signup";
|
import { Signup } from "./Signup";
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ export async function updateForm(data): Promise<SignupForm> {
|
|||||||
|
|
||||||
export const signupFormSendEmail = async (data, id): Promise<any> => {
|
export const signupFormSendEmail = async (data, id): Promise<any> => {
|
||||||
try {
|
try {
|
||||||
const resp = await axios.post(`${process.env.API_URL}/signupForm/${id}/sendemail/`, data, {
|
const resp = await axios.post(`${process.env.NEXT_PUBLIC_API_URL}/signupForm/${id}/sendemail/`, data, {
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": getAuthHeader(),
|
"Authorization": getAuthHeader(),
|
||||||
},
|
},
|
||||||
@@ -95,7 +95,7 @@ export const signupFormSendEmail = async (data, id): Promise<any> => {
|
|||||||
|
|
||||||
export const getSignups = async (id): Promise<Signup[]> => {
|
export const getSignups = async (id): Promise<Signup[]> => {
|
||||||
try {
|
try {
|
||||||
const resp = await axios.get(`${process.env.API_URL}/signupForm/${id}/signups/`, {
|
const resp = await axios.get(`${process.env.NEXT_PUBLIC_API_URL}/signupForm/${id}/signups/`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": getAuthHeader(),
|
"Authorization": getAuthHeader(),
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const url = `${process.env.API_URL}/tags/`;
|
const url = `${process.env.NEXT_PUBLIC_API_URL}/tags/`;
|
||||||
|
|
||||||
export interface Tag {
|
export interface Tag {
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
+10
-18
@@ -1,8 +1,8 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { Helmet } from "react-helmet";
|
import { Helmet } from "react-helmet";
|
||||||
import { Redirect } from "react-router-dom";
|
import { withRouter } from "next/router";
|
||||||
import qs from "query-string";
|
import { WithRouterProps } from "next/dist/client/with-router";
|
||||||
import { generateToken, setTokenCookie, isAuthenticated } from "@utils/auth";
|
import { generateToken, setTokenCookie, isAuthenticated } from "@utils/auth";
|
||||||
|
|
||||||
const Main = styled.div`
|
const Main = styled.div`
|
||||||
@@ -11,14 +11,7 @@ const Main = styled.div`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
interface AdminLoginPageProps {
|
type AdminLoginPageProps = WithRouterProps;
|
||||||
history: {
|
|
||||||
push: (to: string | string[]) => void;
|
|
||||||
};
|
|
||||||
location: {
|
|
||||||
search: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
interface AdminLoginPageState {
|
interface AdminLoginPageState {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
@@ -52,7 +45,7 @@ class AdminLoginPage extends React.Component<AdminLoginPageProps, AdminLoginPage
|
|||||||
handleSubmit = async (e) => {
|
handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const { username, password } = this.state;
|
const { username, password } = this.state;
|
||||||
const { history } = this.props;
|
const { router } = this.props;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const token = await generateToken(username, password);
|
const token = await generateToken(username, password);
|
||||||
@@ -60,7 +53,7 @@ class AdminLoginPage extends React.Component<AdminLoginPageProps, AdminLoginPage
|
|||||||
setTokenCookie(token);
|
setTokenCookie(token);
|
||||||
|
|
||||||
const next = this.getRedirectURL();
|
const next = this.getRedirectURL();
|
||||||
history.push(next);
|
router.push(next);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({
|
this.setState({
|
||||||
error: "Failed to log in!",
|
error: "Failed to log in!",
|
||||||
@@ -93,20 +86,19 @@ class AdminLoginPage extends React.Component<AdminLoginPageProps, AdminLoginPage
|
|||||||
}
|
}
|
||||||
|
|
||||||
getRedirectURL = () => {
|
getRedirectURL = () => {
|
||||||
const { location } = this.props;
|
const { router: { query } } = this.props;
|
||||||
const { search } = location;
|
const { next } = query;
|
||||||
const params = qs.parse(search);
|
|
||||||
const { next } = params;
|
|
||||||
// TODO: Any change of next being string[]? We get type error on without the cast.
|
// TODO: Any change of next being string[]? We get type error on without the cast.
|
||||||
return next as string || DEFAULT_REDIRECT;
|
return next as string || DEFAULT_REDIRECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { router } = this.props;
|
||||||
const { username, password, isAuthenticated } = this.state;
|
const { username, password, isAuthenticated } = this.state;
|
||||||
const next = this.getRedirectURL();
|
const next = this.getRedirectURL();
|
||||||
|
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
return <Redirect to={next} />;
|
router.push(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -133,4 +125,4 @@ class AdminLoginPage extends React.Component<AdminLoginPageProps, AdminLoginPage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AdminLoginPage;
|
export default withRouter(AdminLoginPage);
|
||||||
|
|||||||
@@ -1,21 +1,12 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Redirect } from "react-router-dom";
|
import { useRouter } from "next/router";
|
||||||
import { deleteTokenCookie } from "@utils/auth";
|
import { deleteTokenCookie } from "@utils/auth";
|
||||||
|
|
||||||
export interface AdminLogoutPageProps {}
|
const AdminLogoutPage: React.FC = () => {
|
||||||
export interface AdminLogoutPageState {}
|
deleteTokenCookie();
|
||||||
|
const router = useRouter();
|
||||||
class AdminLogoutPage extends React.Component<AdminLogoutPageProps, AdminLogoutPageState> {
|
router.push("/admin/login");
|
||||||
constructor(props) {
|
return null;
|
||||||
super(props);
|
|
||||||
deleteTokenCookie();
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<Redirect to="/admin/login" />
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AdminLogoutPage;
|
export default AdminLogoutPage;
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
|
||||||
const tokenUrl = `${process.env.API_URL}/api-token-auth/`;
|
const tokenUrl = `${process.env.NEXT_PUBLIC_API_URL}/api-token-auth/`;
|
||||||
const checkUrl = `${process.env.API_URL}/api-token-verify/`;
|
const checkUrl = `${process.env.NEXT_PUBLIC_API_URL}/api-token-verify/`;
|
||||||
|
|
||||||
export async function generateToken(username: string, password: string): Promise<string> {
|
export async function generateToken(username: string, password: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user