Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
85417c1
Create index.html
Voidwaker Mar 23, 2024
cc9ec0c
bootstrap up and running
Voidwaker Mar 23, 2024
e73e5c4
added nav bar and some of the login on the homepage
Voidwaker Mar 24, 2024
fe3759f
added all the pages and just some small html
Voidwaker Mar 24, 2024
6f5f94a
added marin to the content
Voidwaker Mar 24, 2024
34a0263
Update index.html
Voidwaker Mar 24, 2024
7ebea2c
html
Voidwaker Mar 24, 2024
d0182b8
sass
Voidwaker Mar 24, 2024
bb9e828
Update index.html
Voidwaker Mar 24, 2024
21bff20
forgot to add a</div>
Voidwaker Mar 24, 2024
f7eb7c3
Update index.html
Voidwaker Mar 25, 2024
2ac0c88
html
Voidwaker Mar 25, 2024
ad9fc71
adding custom colours and fonts to h1 and h1
Voidwaker Apr 2, 2024
2ef8bbc
information
Voidwaker Apr 2, 2024
a9481c6
Update package.json
Voidwaker Apr 2, 2024
eb9def8
added comments, and profile details
Voidwaker Apr 3, 2024
b7fec36
updated nav bar
Voidwaker Apr 3, 2024
c152c9d
got my scss file to work.
Voidwaker Apr 3, 2024
dd1dacc
trying to add custom color
Voidwaker Apr 3, 2024
7bc2668
alignment and scss
Voidwaker Apr 3, 2024
e4f808b
profile page col-10 etc
Voidwaker Apr 3, 2024
e9720d2
Update index.html
Voidwaker Apr 3, 2024
804c505
custom buttons
Voidwaker Apr 3, 2024
3376605
added nav bar and posts to the feed page
Voidwaker Apr 4, 2024
ecbafc7
Update index.html
Voidwaker Apr 4, 2024
072a695
Update index.html
Voidwaker Apr 4, 2024
9f925e5
trying to get custm button to work
Voidwaker Apr 4, 2024
cad1710
custom button trouble
Voidwaker Apr 4, 2024
5b0f2bb
still problems with custom buittons
Voidwaker Apr 4, 2024
c9b292f
scss not workign propparly
Voidwaker Apr 4, 2024
0e66b58
bullshit
Voidwaker Apr 4, 2024
1762614
no idea how, but it woeked.
Voidwaker Apr 4, 2024
d122829
Update index.html
Voidwaker Apr 4, 2024
a7e88b5
Update index.html
Voidwaker Apr 4, 2024
ecfde14
Update index.html
Voidwaker Apr 4, 2024
154d9b5
custom copulors on text
Voidwaker Apr 4, 2024
e81e41b
njkoløfd
Voidwaker Apr 4, 2024
a6792cd
Update index.html
Voidwaker Apr 4, 2024
badfad5
Update index.html
Voidwaker Apr 5, 2024
01756f6
custom green
Voidwaker Apr 5, 2024
1b3069a
still problems with sass and customize things
Voidwaker Apr 5, 2024
8971254
still no luck with the custom colors
Voidwaker Apr 5, 2024
69105a7
Update package-lock.json
Voidwaker Apr 5, 2024
5aa8f5a
tying to get this to work
Voidwaker Apr 5, 2024
2b162db
still truyig toi fuguyre oyt why iots not workiugn
Voidwaker Apr 5, 2024
33693b7
im going to get mental problems over this
Voidwaker Apr 5, 2024
1707e4f
fuyck this shit
Voidwaker Apr 5, 2024
8df0084
Update _variables.scss
Voidwaker Apr 5, 2024
3e4ee9c
Update index.html
Voidwaker Apr 5, 2024
a2df904
think its fixed now i have noe idea but i think its fixed
Voidwaker Apr 5, 2024
bce0a37
Update index.html
Voidwaker Apr 5, 2024
fe46c92
not workig (custotext-green)
Voidwaker Apr 5, 2024
33cbbab
think maby its fixed now, but not sure
Voidwaker Apr 5, 2024
8d1db5c
text-green (custom text color to match buttons
Voidwaker Apr 5, 2024
5dc4890
Update index.html
Voidwaker Apr 5, 2024
d1dbadd
text-green and text-blue
Voidwaker Apr 5, 2024
117f582
Update index.html
Voidwaker Apr 5, 2024
9f389f0
Update index.html
Voidwaker Apr 5, 2024
77faf86
custom font-family
Voidwaker Apr 7, 2024
fcd3485
Update index.html
Voidwaker Apr 7, 2024
972f211
Update index.html
Voidwaker Apr 7, 2024
c34302f
Update index.html
Voidwaker Apr 7, 2024
e64ba35
Update index.html
Voidwaker Apr 7, 2024
1de3247
some last minute alignment
Voidwaker Apr 7, 2024
57e084b
Update index.html
Voidwaker Apr 7, 2024
a29ee5f
had forgot to switch from norwegian to english
Voidwaker Apr 10, 2024
9ad4447
removed <link rel=stylesheet
Voidwaker Apr 11, 2024
52ef317
removed <lin rel=
Voidwaker Apr 11, 2024
3c6da6e
Update index.html
Voidwaker Apr 11, 2024
ab53cb9
added custom follow button
Voidwaker Apr 11, 2024
b0d3a8e
fixing horisontal scrollbar
Voidwaker Apr 11, 2024
ff7387e
Update index.html
Voidwaker Apr 11, 2024
8309d39
form validation
Voidwaker Apr 11, 2024
41d7765
Update index.html
Voidwaker Apr 11, 2024
2ef64ac
Update index.html
Voidwaker Apr 11, 2024
b255797
Update index.html
Voidwaker Apr 11, 2024
4aa6fe6
Update index.html
Voidwaker Apr 11, 2024
78d2289
Update index.html
Voidwaker Apr 11, 2024
4539ecd
Update index.html
Voidwaker Apr 11, 2024
c63a4d4
deleted index.css and index.map.css files
Voidwaker Apr 12, 2024
aef60f8
remove dist/css from tracking
Voidwaker Apr 15, 2024
0c06482
removed a button
Voidwaker Apr 16, 2024
204a782
trying to fix 405 error
Voidwaker Apr 16, 2024
40bf06a
Update index.html
Voidwaker Apr 16, 2024
26e343f
dev independencies
Voidwaker Apr 16, 2024
db68456
live-server
Voidwaker Apr 19, 2024
e458555
Update index.html
Voidwaker Apr 19, 2024
42643b3
api
Voidwaker May 12, 2024
d03192a
forms
Voidwaker May 12, 2024
2b0e5fd
Update index.html
Voidwaker May 12, 2024
8fe756b
Update index.html
Voidwaker May 12, 2024
eef5e40
form
Voidwaker May 12, 2024
4819fd3
register form fixed
Voidwaker May 12, 2024
ba409a8
login form
Voidwaker May 12, 2024
a4db607
login
Voidwaker May 12, 2024
9972362
redid my login and register
Voidwaker May 13, 2024
e87a74a
form
Voidwaker May 13, 2024
6a4326d
redid the register form js
Voidwaker May 13, 2024
5a61ea2
login/register
Voidwaker May 13, 2024
a3d9561
form
Voidwaker May 13, 2024
4480e90
accestoken error
Voidwaker May 13, 2024
3d7a09f
fixed login
Voidwaker May 14, 2024
d28d795
added local storage
Voidwaker May 16, 2024
22be1b3
alert when registration is sucessful
Voidwaker May 16, 2024
62376d4
login alert
Voidwaker May 16, 2024
927b332
update,read,delete posts
Voidwaker May 16, 2024
59238b3
create
Voidwaker May 19, 2024
7d6e7a6
create posts
Voidwaker May 19, 2024
6a02d9e
posts
Voidwaker May 20, 2024
6e9dd63
401 error fixed
Voidwaker May 20, 2024
3ba6060
test and fetch
Voidwaker May 20, 2024
e6e0080
fething 100 posts
Voidwaker May 20, 2024
f085ef1
fetching posts
Voidwaker May 20, 2024
b9559f6
fixed html for creating and editing a post
Voidwaker May 20, 2024
aaf3f32
Update index.html
Voidwaker May 21, 2024
a0ba631
posts
Voidwaker May 21, 2024
f3e4c25
Update post.mjs
Voidwaker May 21, 2024
263e1bd
Update updatePost.mjs
Voidwaker May 21, 2024
c64bbd8
Update updatePost.mjs
Voidwaker May 21, 2024
cdde4ca
Update updatePost.mjs
Voidwaker May 21, 2024
cc7e664
delete,sort,update and search
Voidwaker May 21, 2024
0730cfa
removed console.log
Voidwaker May 21, 2024
0f8f2e2
Update README.md
Voidwaker May 21, 2024
f14a339
Update update.mjs
Voidwaker May 22, 2024
b14e87c
Merge branch 'js2-try2' of https://github.com/Voidwaker/css-framework…
Voidwaker May 22, 2024
a4b01c9
updated nav
Voidwaker May 22, 2024
2928a02
some minor improvements
Voidwaker May 22, 2024
566b893
Update README.md
Voidwaker May 22, 2024
f224101
Update README.md
Voidwaker May 22, 2024
f54e8e3
Create createApiKey.mjs
Voidwaker Mar 10, 2025
67148f7
fixed registration and login.
Voidwaker Mar 10, 2025
26adb6c
getProfile.mjs
Voidwaker Mar 12, 2025
c2a3549
fixx: adi key to profile request
Voidwaker Mar 12, 2025
9653024
displaying posts
Voidwaker Mar 13, 2025
3732ffb
removed some comments
Voidwaker Mar 13, 2025
23111b8
create posts
Voidwaker Mar 14, 2025
aba5b7d
Update update.mjs
Voidwaker Mar 17, 2025
f2ffbaa
Update register.mjs
Voidwaker Mar 17, 2025
7a0dbaa
Update login.mjs
Voidwaker Mar 17, 2025
0bcc779
delete.mjs and profile.mjs
Voidwaker Mar 18, 2025
3329b20
Update index.html
Voidwaker Mar 18, 2025
d20f5cf
Update index.mjs
Voidwaker Mar 18, 2025
e631e4c
Update delete.mjs
Voidwaker Mar 18, 2025
e96fdab
errors regarding media url
Voidwaker Mar 18, 2025
5ea500d
logout button
Voidwaker Mar 19, 2025
e324e94
logout, and acces too feed/profiule
Voidwaker Mar 19, 2025
84ab976
Update index.mjs
Voidwaker Mar 19, 2025
9e9446c
Update index.mjs
Voidwaker Mar 19, 2025
67daf56
fixed unautoriced access
Voidwaker Mar 20, 2025
3834a20
Update login.mjs
Voidwaker Mar 20, 2025
830481a
edit post
Voidwaker Mar 20, 2025
66ccd8e
Update index.mjs
Voidwaker Mar 20, 2025
a612d0e
sorting and jsDocs
Voidwaker Mar 22, 2025
896ab8a
Update createApiKey.mjs
Voidwaker Mar 22, 2025
a78ebd1
Update login.mjs
Voidwaker Mar 22, 2025
612bc69
Update register.mjs
Voidwaker Mar 22, 2025
339de89
Update create.mjs
Voidwaker Mar 22, 2025
62585c8
Update delete.mjs
Voidwaker Mar 22, 2025
3c8b2d2
Update read.mjs
Voidwaker Mar 22, 2025
5e5b81b
Update update.mjs
Voidwaker Mar 22, 2025
a13981d
Update getProfile.mjs
Voidwaker Mar 22, 2025
017ad99
Update constants.mjs
Voidwaker Mar 22, 2025
f5ba40f
Update createPost.mjs
Voidwaker Mar 22, 2025
135e417
Update login.mjs
Voidwaker Mar 22, 2025
a5f50a8
Update logout.mjs
Voidwaker Mar 22, 2025
ee90d24
profile.mjs and delete.mjs
Voidwaker Mar 22, 2025
611ebd8
Update register.mjs
Voidwaker Mar 22, 2025
73ac341
Update updatePost.mjs
Voidwaker Mar 22, 2025
2575fff
aded view more modal
Voidwaker Mar 22, 2025
286a46c
feed
Voidwaker Mar 22, 2025
9989d32
unautorized access
Voidwaker Mar 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules/
.DS_Store
dist/
dist/
117 changes: 115 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,115 @@
# css-frameworks-ca
Replace this text with a description of your social media project.
## js2 social media application
link to trello: https://trello.com/invite/b/HgMSDygC/ATTI59165adf424964b1c8ef6ef67039647001A570D6/javascrip2

this is my "social media application" you can register a user (with a valid @noroff(stud.noroff.no). the registerd ouser can login, make posts, edit posts and delete posts. and view others posts.
navigation is clear on the homepage(login) wher there is a button for registration and after registration, there is a button for login, when u have gotten the confiramtion that your logged inn, use the nav bar to get to feed or profile.


---
### made with:
<img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/HTML.svg" width="50" height="50">
<img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/CSS.svg" width="50" height="50">
<img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/JavaScript.svg" width="50" height="50">
<img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/VSCode-Dark.svg" width="50" height="50"> <img
---

Description--

## Brief
You have been tasked with producing a new JavaScript front-end client for an existing social media platform. The client application must be attractive and responsive, but you have an otherwise blank slate in terms of theme design language.

Using the provided API and API documentation, create a functioning user interface that allows for viewing, posting, editing and deleting social media content.

Social API routes require authorisation via JWT (JSON Web Tokens). You will need to register an account and login to access your token.

To complete the required features, you will also need to make use of GET, POST, PUT, and DELETE HTTP methods.

Using localStorage is highly recommended, especially for storing JWT tokens.

A finished project fulfils the requirements below with an easy to use and error-free user interface.

Required features
The following user stories are required for a passing submission:

User with @noroff.no or @stud.noroff.no email can register profile
Registered user can login
User can view a post content feed
User can filter the post content feed
User can search the post content feed
User can view a post content item by ID
User can create a post content item
User can update a post content item
User can delete a post content item
Additional features
The following user stories are optional:

User can create a comment on a post
User can edit profile media
User can follow/unfollow a profile
User can react to a post content item

## register
here u can register a profile with a @noroff.no or @stud.noroff.no email, when registrering, you will get a confimation if the registration is successfull, and you will get a error message if the registration was unsucessfull.

## login
after registring a user, you can take the same email and password and login.

## feed
in the feed page, when you have logged inn, you can create a post (with a title, body,tags(optionale) and media(optionale) further down the page, u can update(edit) a post that you have created,just click on the edit button on the post u want to edit (to get the post id) .you can also delete a post, if you are unhappy, or if u dont want it out there, its simple, just click on the delete button on the post u want to delete (to get the post id so the post can be deleted)
we have a search fuction, if u wanna see 100 posts of "test" just search test or example"
after that we have a sorting option, where the default is newest, but if you set it to the oldest, the oldests posts (out of the 100 fetched) is being displayed first.
last we have the feed, here you can see the time the posts, the time the have beed posted.

## profile

here you can see your profile
i did not get time to make the profile page alot of the things was optionale, so hopefully you can atleast edit your bio, and mabye press the follow button.

#### Getting Started

Installing

Clone the repo:

git clone git@github.com: https://github.com/Voidwaker/css-frameworks-ca/tree/js2-try2

Install the dependencies: N/A

npm install

Running

To run the app, run the following commands:

npm run dev





---

Contributing


As this is my js2 assignment, i dont want contributions, but feedback to how i can imporve the site is always velcome. Thank you!

Any suggestions will be happily taken into account- feel free to message me!
---

Contact:


Email me:
Sigurdvaaler@hotmail.com

<img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/Gmail-Dark.svg" width="50" height="50"> <img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/Discord.svg" width="50" height="50">


Find me on Discord:
(Sigurd Vaaler
Voidwaker1)

---

Acknowledgments:
99 changes: 99 additions & 0 deletions feed/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Feed</title>
<link rel="stylesheet" href="/dist/css/index.css" />
<script defer src="/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script type="module" src="/js/index.mjs" defer></script>
</head>
<body class="bg-dark">
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="/">Home</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/profile">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="/feed/index.html">Feed</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<main class="container mt-4">
<div class="card border-dark mb-3 mx-auto">
<div class="card-body">
<h5 class="card-title mb-3 text-green text-center">Create New Post</h5>
<form id="createPost">
<div class="form-group mb-3 text-green">
<label for="postTitle">Title</label>
<input class="form-control" type="text" id="postTitle" name="title" required />
</div>
<div class="form-group mb-3 text-green">
<label for="postBody">Body</label>
<textarea class="form-control" id="postBody" name="body" required></textarea>
</div>
<div class="form-group mb-3 text-green">
<label for="postTags">Tags (comma separated)</label>
<input class="form-control" type="text" id="postTags" name="tags" />
</div>
<div class="form-group mb-3 text-green">
<label for="postMedia">Media</label>
<input class="form-control" type="url" id="postMedia" name="media" />
</div>
<div class="d-flex justify-content-center">
<button class="btn btn-success" type="submit">Create Post</button>
</div>
</form>
</div>
</div>
<div class="d-flex justify-content-center mb-3">
<div class="col-md-6 col-lg-4">
<select id="filterPosts" class="form-control text-green">
<option value="newest">Newest</option>
<option value="oldest">Oldest</option>
<option value="popular">Most Popular</option>
</select>
</div>
</div>
<div class="d-flex justify-content-center mb-3">
<div class="col-md-8">
<input id="searchPosts" type="text" class="form-control text-green" placeholder="Search for posts..." />
</div>
</div>
<h1 class="fst-italic fw-bold text-center">Posts</h1>
<div id="posts" class="mt-4"></div>
</main>
<div class="modal fade" id="viewPostModal" tabindex="-1" aria-labelledby="viewPostModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content bg-dark text-green">
<div class="modal-header">
<h5 class="modal-title" id="viewPostModalLabel">Post Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h5 id="viewPostTitle" class="text-green"></h5>
<p id="viewPostBody" class="text-green"></p>
<p class="text-green"><strong>Author:</strong> <span id="viewPostAuthor"></span></p>
<p class="text-green"><strong>Posted:</strong> <span id="viewPostDate"></span></p>
<div id="viewPostMedia" class="mt-3"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>

56 changes: 56 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login/Registrer</title>
<link rel="stylesheet" href="dist/css/index.css">
<script defer src="node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script type="module" src="./js/index.mjs" defer></script>
</head>
<body class="bg-dark">
<header class="container-fluid">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="/">Home</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/profile">Profil</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/feed/index.html">Feed</a>
</li>
<li class="nav-item">
<button id="logoutBtn" class="btn btn-danger">Logout</button>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container-sm col-6 mt-5">
<h2 class="text-center">Logg Inn</h2>
<form id="loginForm">
<div class="mb-3">
<label for="loginEmail" class="form-label text-blue">E-post</label>
<input type="email" class="form-control text-green" id="loginEmail" name="email" placeholder="Email@example.com" required>
</div>
<div class="mb-3">
<label for="loginPassword" class="form-label text-blue">Passord</label>
<input type="password" class="form-control text-green" id="loginPassword" name="password" placeholder="Password" required minlength="8">
</div>
<div class="d-flex justify-content-center">
<button type="submit" class="btn btn-custom">Logg Inn</button>
</div>
</form>
<div id="errorDisplay" style="color: red;"></div>
<div class="d-flex justify-content-center mt-3">
<a href="register.html" class="btn btn-custom">Register</a>
</div>
</div>
</body>
</html>
81 changes: 81 additions & 0 deletions js/api/auth/authFetch.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { load, remove } from "../../storage/index.mjs";
import { API_KEY_STORAGE, API_TOKEN_STORAGE } from "../constants.mjs";

/**
* Generates headers for an authenticated API request.
* Includes Authorization and X-Noroff-API-Key if available in localStorage.
*
* @returns {Object} Headers object for fetch.
*/
export function headers() {
const token = load(API_TOKEN_STORAGE);
const apiKey = load(API_KEY_STORAGE);

if (!token || !apiKey) {
return {};
}

return {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
"X-Noroff-API-Key": apiKey
};
}

/**
* Makes an authenticated fetch request using stored token and API key.
*
* @param {string} url - The endpoint to send the request to.
* @param {Object} [options={}] - Optional fetch options.
* @returns {Promise<Response>} The fetch response object.
* @throws {Error} Throws if the fetch fails or the response is not OK.
*/
export async function authFetch(url, options = {}) {
const requestOptions = {
...options,
headers: {
...headers(),
...options.headers
}
};

try {
const response = await fetch(url, requestOptions);

if (!response.ok) {
const errorData = await response.json();
const status = response.status;
const message = errorData?.errors?.[0]?.message || "Unknown error";

if (status === 401) {
remove(API_TOKEN_STORAGE);
remove(API_KEY_STORAGE);
remove("profile");

document.body.innerHTML = `
<div style="position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background-color: red; color: white; padding: 10px; border-radius: 5px; z-index: 1000;">
❌ You must be logged in to access this page. Redirecting to login...
</div>
`;

setTimeout(() => {
window.location.href = "/index.html";
}, 1500);

return;
}

throw new Error(`HTTP error! status: ${status}, message: ${message}`);
}

return response;
} catch (error) {
console.error("❌ Fetch error:", error);
throw error;
}
}





Loading