bleh
This commit is contained in:
parent
71266e79f6
commit
5846e35e81
1 changed files with 8 additions and 3 deletions
11
src/main.ts
11
src/main.ts
|
@ -1,4 +1,4 @@
|
||||||
import Fastify from 'fastify'
|
import Fastify, {FastifyRequest} from 'fastify'
|
||||||
import {PrismaClient} from '@prisma/client'
|
import {PrismaClient} from '@prisma/client'
|
||||||
import fastifyMultipart from "@fastify/multipart";
|
import fastifyMultipart from "@fastify/multipart";
|
||||||
import fastifyOauth2 from "@fastify/oauth2";
|
import fastifyOauth2 from "@fastify/oauth2";
|
||||||
|
@ -21,6 +21,7 @@ if (!process.env.ORIGIN) {
|
||||||
console.error("no origin found");
|
console.error("no origin found");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
let isDev = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
const FILESIZE = process.env.FILESIZE_LIMIT
|
const FILESIZE = process.env.FILESIZE_LIMIT
|
||||||
if (!FILESIZE) {
|
if (!FILESIZE) {
|
||||||
|
@ -51,6 +52,9 @@ const fastify = Fastify({logger: true})
|
||||||
|
|
||||||
|
|
||||||
fastify.register(fastifyMultipart)
|
fastify.register(fastifyMultipart)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fastify.register(fastifyOauth2, {
|
fastify.register(fastifyOauth2, {
|
||||||
name: 'discordOAuth2',
|
name: 'discordOAuth2',
|
||||||
credentials: {
|
credentials: {
|
||||||
|
@ -62,7 +66,8 @@ fastify.register(fastifyOauth2, {
|
||||||
},
|
},
|
||||||
scope: ["identify"],
|
scope: ["identify"],
|
||||||
startRedirectPath: '/login',
|
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) {
|
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});
|
return reply.send({access_token: refreshToken.access_token});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue