Full-Stack Blog Application with Spring Boot Backend and Secure Redux Frontend
With Next.js and TypeScript, you can build a secure, high-performance, SEO-friendly blog platform with minimal effort. This guide covers setting up Redux Toolkit, JWT authentication (admin only), and best practices for a clean, modular Next.js structure.
π Why Next.js + TypeScript?
- Type safety and reduced runtime bugs
- Server-side rendering and SEO out of the box
- Built-in routing and performance optimizations
- Excellent DX (developer experience)
π Step-by-Step Installation Guide
π§° Prerequisites
- Node.js v18+
- Java JDK 17+
- npm or yarn
π¦ Create a New Next.js 15 App with TypeScript
npx create-next-app@latest nextjs-blog --typescript
cd nextjs-blog
π§ Install Required Packages
npm install @reduxjs/toolkit react-redux axios npm install --save-dev @types/react-redux
π Setup .env.local
NEXT_PUBLIC_API_URL=http://localhost:8080/api
π Project Folder Structure (Next.js + TypeScript + Redux + Spring Boot Backend)
nextjs-blog/
β
βββ public/
β
βββ src/
β βββ app/
β β βββ store.ts β Redux store setup
β
β βββ api/
β β βββ axiosInstance.ts β Axios with JWT interceptors
β
β βββ features/
β β βββ auth/
β β β βββ authSlice.ts β Login/logout JWT state
β β β βββ authAPI.ts β Auth endpoints
β β βββ posts/
β β β βββ postSlice.ts β Post list state
β β β βββ postAPI.ts β Post endpoints (CRUD)
β β βββ categories/
β β β βββ categorySlice.ts
β β β βββ categoryAPI.ts
β β βββ comments/
β β βββ commentSlice.ts
β β βββ commentAPI.ts
β
β βββ components/
β β βββ admin/
β β β βββ AdminSidebar.tsx β Sidebar for admin panel
β β βββ frontend/
β β βββ Navbar.tsx β Blog navigation
β β βββ PostCard.tsx β Individual post display
β β βββ CommentBox.tsx β Comment input + list
β
β βββ layouts/
β β βββ AdminLayout.tsx β Admin UI container
β β βββ FrontLayout.tsx β Public blog layout
β
β βββ auth/
β β βββ PrivateRoute.tsx β Admin route protection (JWT)
β
β βββ middleware/ β (Optional for edge auth)
β
β βββ pages/
β β βββ _app.tsx β Wrap app with Redux Provider
β β βββ index.tsx β Blog homepage
β β βββ about.tsx β Static about page
β β βββ post/[id].tsx β Dynamic post view
β β βββ category/[id].tsx β Filtered post view
β β βββ admin/
β β βββ login.tsx β Admin login page
β β βββ dashboard.tsx β Admin dashboard summary
β β βββ posts.tsx β Manage blog posts
β β βββ categories.tsx β Manage categories
β β βββ comments.tsx β Moderate comments
β
βββ tsconfig.json β TypeScript config
βββ .env.local β API base, secrets
βββ next.config.js β Next.js config
βββ package.json β Dependencies
π§ Setting Up Redux Toolkit in Next.js
store.ts
// src/app/store.ts
import { configureStore } from '@reduxjs/toolkit';
import authReducer from '../features/auth/authSlice';
export const store = configureStore({
reducer: {
auth: authReducer,
},
});
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
_app.tsx
// pages/_app.tsx
import { Provider } from 'react-redux';
import { store } from '../app/store';
import type { AppProps } from 'next/app';
function MyApp({ Component, pageProps }: AppProps) {
return (
<Provider store={store}>
<Component {...pageProps} />
</Provider>
);
}
export default MyApp;
π Admin Authentication with JWT
authSlice.ts
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import axios from '../../api/axiosInstance';
interface AuthState {
token: string | null;
status: 'idle' | 'loading' | 'succeeded' | 'failed';
error: string | null;
}
const initialState: AuthState = {
token: typeof window !== 'undefined' ? localStorage.getItem('token') : null,
status: 'idle',
error: null,
};
export const login = createAsyncThunk(
'auth/login',
async (credentials: { email: string; password: string }) => {
const res = await axios.post('/auth/login', credentials);
return res.data.token;
}
);
π§Ύ Admin Pages (Protected)
- /admin/login.tsx β Login form
- /admin/dashboard.tsx β Summary and metrics
- /admin/posts.tsx β Manage posts
- /admin/comments.tsx β Approve comments
π Frontend Pages (Public)
- /index.tsx β Home
- /post/[id].tsx β Post Details
- /category/[id].tsx β Category Filter
- /about.tsx β Static Info
β Deployment Tips
- Use Vercel for frontend hosting
- Deploy Spring Boot API on Render or Railway
- Store API base in
.env.local
asNEXT_PUBLIC_API_URL
π― Final Thoughts
With this setup, you now have a robust Next.js blog system with admin-only JWT protection, full Redux state management, and a flexible codebase ready for future expansionβimage uploads, rich-text editor, comment replies, and beyond.