Skip to content

Commit

Permalink
feat: make oauth great again!
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 13, 2024
1 parent ab0db00 commit ee0fc7a
Show file tree
Hide file tree
Showing 61 changed files with 1,695 additions and 1,200 deletions.
10 changes: 0 additions & 10 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,5 @@ NEXT_PUBLIC_GATEWAY_URL=http://127.0.0.1:2333/
NEXT_PUBLIC_API_URL=https://innei.ren/api/v2
NEXT_PUBLIC_GATEWAY_URL=https://api.innei.ren

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_aaaaaaaaaaaaaaaaaxxxxxx

## Clerk
CLERK_SECRET_KEY=sk_test_

NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/

TMDB_API_KEY=
GH_TOKEN=
10 changes: 3 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@ WORKDIR /app

COPY . .


RUN npm install -g pnpm
RUN pnpm install

FROM base AS builder

RUN apk update && apk add --no-cache git


WORKDIR /app
COPY --from=deps /app/ .
RUN npm install -g pnpm

ENV NODE_ENV production
ARG BASE_URL
ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
ARG CLERK_SECRET_KEY

ARG S3_ACCESS_KEY
ARG S3_SECRET_KEY
ARG WEBHOOK_SECRET
Expand All @@ -36,8 +33,7 @@ ARG GH_TOKEN
ENV BASE_URL=${BASE_URL}
ENV NEXT_PUBLIC_API_URL=${BASE_URL}/api/v2
ENV NEXT_PUBLIC_GATEWAY_URL=${BASE_URL}
ENV NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=${NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY}
ENV CLERK_SECRET_KEY=${CLERK_SECRET_KEY}

ENV S3_ACCESS_KEY=${S3_ACCESS_KEY}
ENV S3_SECRET_KEY=${S3_SECRET_KEY}
ENV TMDB_API_KEY=${TMDB_API_KEY}
Expand All @@ -61,4 +57,4 @@ EXPOSE 2323

ENV PORT 2323
ENV NEXT_SHARP_PATH=/usr/local/lib/node_modules/sharp
CMD echo "Mix Space Web [Shiro] Image." && node server.js;
CMD echo "Mix Space Web [Shiro] Image." && node server.js
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
},
"dependencies": {
"@aws-sdk/client-s3": "3.649.0",
"@clerk/nextjs": "5.5.1",
"@clerk/themes": "2.1.29",
"@excalidraw/excalidraw": "0.17.6",
"@floating-ui/react-dom": "2.1.1",
"@milkdown/core": "7.5.0",
Expand All @@ -42,7 +40,9 @@
"@milkdown/utils": "7.5.0",
"@mx-space/api-client": "1.15.0",
"@prosemirror-adapter/react": "0.2.6",
"@radix-ui/react-avatar": "1.1.0",
"@radix-ui/react-dialog": "1.1.1",
"@radix-ui/react-dropdown-menu": "2.1.1",
"@radix-ui/react-label": "2.1.0",
"@radix-ui/react-scroll-area": "1.1.0",
"@radix-ui/react-select": "2.1.1",
Expand Down Expand Up @@ -85,6 +85,7 @@
"mermaid": "11.2.0",
"nanoid": "^5.0.7",
"next": "14.2.9",
"next-auth": "4.24.7",
"next-runtime-env": "3.2.2",
"next-themes": "0.3.0",
"ofetch": "1.3.4",
Expand Down Expand Up @@ -155,6 +156,7 @@
"tailwind-scrollbar": "3.1.0",
"tailwind-variants": "0.2.1",
"tailwindcss": "^3.4.10",
"tailwindcss-animate": "1.0.7",
"tailwindcss-animated": "1.1.2",
"typescript": "5.6.2",
"zx": "8.1.6"
Expand Down Expand Up @@ -202,4 +204,4 @@
"browserslist": [
"defaults and fully supports es6-module"
]
}
}
10 changes: 2 additions & 8 deletions packages/fetch/src/fetch.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import { createFetch } from 'ofetch'

import PKG from '~/../package.json'

import {
ClerkCookieKey,
createApiClient,
createFetchAdapter,
TokenKey,
} from './shared'
import { createApiClient, createFetchAdapter, TokenKey } from './shared'

const isDev = process.env.NODE_ENV === 'development'
export const $fetch = createFetch({
Expand All @@ -20,9 +15,8 @@ export const $fetch = createFetch({

onRequest(context) {
const cookie = cookies()
const clerkJwt = cookie.get(ClerkCookieKey)?.value

const token = cookie.get(TokenKey)?.value || clerkJwt
const token = cookie.get(TokenKey)?.value

const headers: any = context.options.headers ?? {}
if (token) {
Expand Down
9 changes: 2 additions & 7 deletions packages/fetch/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,10 @@ export const createApiClient = (

export const TokenKey = 'mx-token'

export const ClerkCookieKey = '__session'
export const AuthKeyNames = [TokenKey, ClerkCookieKey]
export const AuthKeyNames = [TokenKey]

export function getToken(): string | null {
// FUCK clerk constants not export, and mark it internal and can not custom
// packages/backend/src/constants.ts
const clerkJwt = Cookies.get(ClerkCookieKey)

const token = Cookies.get(TokenKey) || clerkJwt
const token = Cookies.get(TokenKey)

return token || null
}
Loading

0 comments on commit ee0fc7a

Please sign in to comment.