This commit is contained in:
amy 2024-12-03 07:46:36 +03:30
parent 71266e79f6
commit 5846e35e81
Signed by: amy
SSH key fingerprint: SHA256:Y6VEv6ZOxI6zqjjOF4luhfaCoY+zDK0w62P+qhQYie4

View file

@ -1,4 +1,4 @@
import Fastify from 'fastify'
import Fastify, {FastifyRequest} from 'fastify'
import {PrismaClient} from '@prisma/client'
import fastifyMultipart from "@fastify/multipart";
import fastifyOauth2 from "@fastify/oauth2";
@ -21,6 +21,7 @@ if (!process.env.ORIGIN) {
console.error("no origin found");
process.exit(1);
}
let isDev = process.env.NODE_ENV !== 'production';
const FILESIZE = process.env.FILESIZE_LIMIT
if (!FILESIZE) {
@ -51,6 +52,9 @@ const fastify = Fastify({logger: true})
fastify.register(fastifyMultipart)
fastify.register(fastifyOauth2, {
name: 'discordOAuth2',
credentials: {
@ -62,7 +66,8 @@ fastify.register(fastifyOauth2, {
},
scope: ["identify"],
startRedirectPath: '/login',
callbackUri: req => `${process.env.ORIGIN}/login/callback`,
callbackUri: (isDev ? (req) => `${req.protocol}://${req.host}/login/callback` : `${process.env.ORIGIN}/login/callback`),
})
fastify.get('/login/callback', async function (request, reply) {
@ -103,7 +108,7 @@ fastify.get('/login/callback', async function (request, reply) {
},
})
}
reply.setCookie('access_token', refreshToken.discordToken);
reply.setCookie('access_token', refreshToken.access_token);
return reply.send({access_token: refreshToken.access_token});
});