irlandrew
irlandrew
DDeno
Created by irlandrew on 11/26/2024 in #help
cors header issue
Used cors from hono, as wiki says: app.use( '*', cors({ origin: ['http://localhost:5173'], allowHeaders: ['Content-Type', 'Authorization'], allowMethods: ['GET', 'POST', 'OPTIONS'], credentials: true, }) ); at the beginning and worked for me
11 replies
DDeno
Created by irlandrew on 11/26/2024 in #help
cors header issue
Solved
11 replies
DDeno
Created by irlandrew on 11/26/2024 in #help
cors header issue
I'm still in development so thats the reason I'm not using a domain right now
11 replies
DDeno
Created by irlandrew on 11/26/2024 in #help
cors header issue
in Access-Control-Allow-Origin I tried everything localhost, *, 127.0.0.1 , localhost:5173 ...
11 replies
DDeno
Created by irlandrew on 11/26/2024 in #help
cors header issue
Yes but I do have it written:
app.use('*', async (c, next) => {
c.header('Access-Control-Allow-Origin', 'http://localhost:5173/*');
c.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
c.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
c.header('Access-Control-Allow-Credentials', 'true');

if (c.req.method === 'OPTIONS') {
return c.text('', 204);
}

await next();
});
app.use('*', async (c, next) => {
c.header('Access-Control-Allow-Origin', 'http://localhost:5173/*');
c.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
c.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
c.header('Access-Control-Allow-Credentials', 'true');

if (c.req.method === 'OPTIONS') {
return c.text('', 204);
}

await next();
});
11 replies
DDeno
Created by irlandrew on 11/26/2024 in #help
cors header issue
Not sure how
11 replies
DDeno
Created by irlandrew on 11/26/2024 in #help
cors header issue
And I believe I need to paste all the backend main class
11 replies
DDeno
Created by irlandrew on 11/26/2024 in #help
cors header issue
No description
11 replies
DDeno
Created by irlandrew on 11/26/2024 in #help
cors header issue
Through the client I "login" with this method:
const handleLogin = async () => {
try {

const mojangResponse = await fetch(
`http://localhost:8000/mojang-api/users/profiles/minecraft/${username}`
);

if (!mojangResponse.ok) {
const errorData = await mojangResponse.json();
setError(errorData.error || "Invalid Minecraft username.");
return;
}

const mojangData = await mojangResponse.json();
setSkin(`https://crafatar.com/avatars/${mojangData.id}`);
setError(null);


const fastLoginResponse = await fetch("http://localhost:8000/api/fast-login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username }),
credentials: "include",
});

if (!fastLoginResponse.ok) {
const loginError = await fastLoginResponse.json();
setError(loginError.message || "Error during fast login.");
return;
}


setIsLoggedIn(true);
setError(null);


setTimeout(() => {
onClose();
}, 5000);
} catch (err) {
setError("An error occurred while connecting to the server.");
}
};
const handleLogin = async () => {
try {

const mojangResponse = await fetch(
`http://localhost:8000/mojang-api/users/profiles/minecraft/${username}`
);

if (!mojangResponse.ok) {
const errorData = await mojangResponse.json();
setError(errorData.error || "Invalid Minecraft username.");
return;
}

const mojangData = await mojangResponse.json();
setSkin(`https://crafatar.com/avatars/${mojangData.id}`);
setError(null);


const fastLoginResponse = await fetch("http://localhost:8000/api/fast-login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username }),
credentials: "include",
});

if (!fastLoginResponse.ok) {
const loginError = await fastLoginResponse.json();
setError(loginError.message || "Error during fast login.");
return;
}


setIsLoggedIn(true);
setError(null);


setTimeout(() => {
onClose();
}, 5000);
} catch (err) {
setError("An error occurred while connecting to the server.");
}
};
11 replies