Skip to content

Commit 18beec4

Browse files
authored
feat: add oauth pages & apis (#656)
1 parent 42c09b3 commit 18beec4

File tree

11 files changed

+539
-19
lines changed

11 files changed

+539
-19
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ module.exports = {
125125
'import/first': 'error',
126126
'import/no-duplicates': 'error',
127127
'import/newline-after-import': 'error',
128+
'import/no-named-as-default': 'off',
128129
'simple-import-sort/imports': [
129130
'error',
130131
{

bin/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ logger.info(`GraphQL UI http://127.0.0.1:${port}/v0/altair/`);
3434
logger.info(`private API http://127.0.0.1:${port}/p1/`);
3535
logger.info(`demo http://127.0.0.1:${port}/demo/`);
3636
logger.info(`admin http://127.0.0.1:${port}/demo/admin/`);
37+
logger.info(`oauth http://127.0.0.1:${port}/oauth/authorize`);
3738
logger.flush();

lib/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const pkg = JSON.parse(
5757
export const VERSION = developing ? 'development' : REF || pkg.version;
5858

5959
export const redisPrefix = `graphql-${VERSION}`;
60+
export const redisOauthPrefix = `oauth`;
6061

6162
export { HTTPS_PROXY };
6263

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@esbuild-kit/esm-loader": "^2.6.5",
3030
"@fastify/cookie": "^9.3.1",
3131
"@fastify/error": "^3.4.1",
32+
"@fastify/formbody": "^7.4.0",
3233
"@fastify/static": "^7.0.3",
3334
"@fastify/swagger": "^8.14.0",
3435
"@fastify/view": "^9.1.0",

pnpm-lock.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

routes/demo/index.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import * as path from 'node:path';
22

33
import Cookie from '@fastify/cookie';
44
import { fastifyStatic } from '@fastify/static';
5-
import { fastifyView } from '@fastify/view';
6-
import { Liquid } from 'liquidjs';
75

86
import { cookiesPluginOption } from '@app/lib/auth/session.ts';
9-
import config, { production, projectRoot } from '@app/lib/config.ts';
7+
import config, { projectRoot } from '@app/lib/config.ts';
108
import * as Notify from '@app/lib/notify.ts';
119
import { fetchUserX } from '@app/lib/orm/index.ts';
1210
import * as res from '@app/lib/types/res.ts';
@@ -47,21 +45,6 @@ export async function setup(app: App) {
4745
prefix: '/static/',
4846
});
4947

50-
const liquid = new Liquid({
51-
root: path.resolve(projectRoot, 'templates'),
52-
extname: '.liquid',
53-
cache: production,
54-
});
55-
56-
await app.register(fastifyView, {
57-
engine: {
58-
liquid,
59-
},
60-
defaultContext: { production },
61-
root: path.resolve(projectRoot, 'templates'),
62-
production,
63-
});
64-
6548
await app.register(admin.setup, { prefix: '/admin' });
6649
await app.register(userDemoRoutes);
6750
}

routes/index.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import * as path from 'node:path';
22

33
import { fastifyStatic } from '@fastify/static';
4+
import { fastifyView } from '@fastify/view';
5+
import { Liquid } from 'liquidjs';
46

57
import type { IAuth } from '@app/lib/auth/index.ts';
6-
import { projectRoot } from '@app/lib/config.ts';
8+
import { production, projectRoot } from '@app/lib/config.ts';
79
import { logger } from '@app/lib/logger.ts';
810
import * as demo from '@app/routes/demo/index.ts';
11+
import * as oauth from '@app/routes/oauth/index.ts';
912
import * as privateAPI from '@app/routes/private/index.ts';
1013
import type { App } from '@app/routes/type.ts';
1114

@@ -14,8 +17,24 @@ export async function setup(app: App) {
1417

1518
app.decorateRequest('auth', null);
1619

20+
const liquid = new Liquid({
21+
root: path.resolve(projectRoot, 'templates'),
22+
extname: '.liquid',
23+
cache: production,
24+
});
25+
26+
await app.register(fastifyView, {
27+
engine: {
28+
liquid,
29+
},
30+
defaultContext: { production },
31+
root: path.resolve(projectRoot, 'templates'),
32+
production,
33+
});
34+
1735
await app.register(privateAPI.setup, { prefix: '/p1' });
1836
await app.register(demo.setup, { prefix: '/demo/' });
37+
await app.register(oauth.setup, { prefix: '/oauth/' });
1938

2039
await app.register(fastifyStatic, {
2140
root: path.resolve(projectRoot, 'static/img/'),

0 commit comments

Comments
 (0)