Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade lucia and prisma #8

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/ci-prisma-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: CI-next-prisma

on:
push:
branches:
- main
- major
- minor
- dev
# Only consider those paths to trigger the action
paths:
- 'packages/**'
- 'package.json'
- '*.lock'
- '.yarnrc.yml'
- 'tsconfig.base.json'
- '.prettier*'
- '.github/**'

pull_request:
branches:
- main
- major
- minor
- dev
types:
- opened
- synchronize
- reopened
# Only consider those paths to trigger the action
paths:
- 'packages/**'
- 'package.json'
- '*.lock'
- '.yarnrc.yml'
- 'tsconfig.base.json'
- '.prettier*'
- '.github/**'
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: 📥 Monorepo install
uses: ./.github/actions/yarn-nm-install

- name: Typecheck
working-directory: packages/next-prisma
run: |
yarn typecheck

- name: Linter
working-directory: packages/next-prisma
run: |
yarn lint

- name: Unit tests
working-directory: packages/next-prisma
run: |
yarn test-unit --passWithNoTests

- name: Build next-prisma
working-directory: packages/next-prisma
run: |
yarn build
# commit:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# with:
# ref: main
# - uses: actions/setup-node@v3
# with:
# node-version: 18

# - name: 📥 Monorepo install
# uses: ./.github/actions/yarn-nm-install

# - name: Unit test coverage
# working-directory: packages/next-prisma
# run: |
# yarn test-coverage

# - name: Publish github pages
# run: |
# git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
# git config --global user.name 'hyperse-net'
# git config --global user.email '[email protected]'
# git fetch
# git checkout gb_pages
# mkdir -p ./gb_pages
# cp -R ./packages/next-prisma/coverage/* ./gb_pages/coverage/next-prisma
# git add gb_pages/*
# git commit -m "Update page"
# git push
33 changes: 19 additions & 14 deletions next-mate.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,50 @@
"folders": [
{
"name": "next-demo",
"path": "packages/next-demo"
"path": "packages/next-demo",
},
{
"name": "next-env",
"path": "packages/next-env"
"path": "packages/next-env",
},
{
"name": "next-auth",
"path": "packages/next-auth"
"path": "packages/next-auth",
},
{
"name": "next-core",
"path": "packages/next-core"
"path": "packages/next-core",
},
{
"name": "next-graphql",
"path": "packages/next-graphql"
"path": "packages/next-graphql",
},
{
"name": "next-prisma",
"path": "packages/next-prisma",
},
{
"name": "root",
"path": "."
}
"path": ".",
},
],
"extensions": {
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"],
},
"settings": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "never"
"source.organizeImports": "never",
},
"files.associations": {
"*.css": "tailwindcss"
"*.css": "tailwindcss",
},
// Disable vscode formatting for js,jsx,ts,tsx files
// to allow dbaeumer.vscode-eslint to format them
"[javascript]": {
"editor.formatOnSave": false
"editor.formatOnSave": false,
},
"typescript.enablePromptUseWorkspaceTsdk": true,
// https://github.com/Microsoft/vscode-eslint#mono-repository-setup
Expand All @@ -50,8 +54,9 @@
"./packages/next-env",
"./packages/next-auth",
"./packages/next-core",
"./packages/next-graphql"
"./packages/next-graphql",
"./packages/next-prisma",
],
"typescript.tsdk": "root/node_modules/typescript/lib"
}
"typescript.tsdk": "root/node_modules/typescript/lib",
},
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
},
"resolutions": {
"@flatjs/forge": "2.0.0",
"@prisma/client": "5.7.0",
"@lucia-auth/adapter-prisma": "^3.0.2"
"@prisma/client": "5.13.0"
},
"dependencies": {
"cross-env": "7.0.3"
Expand Down
34 changes: 34 additions & 0 deletions packages/next-auth/copyPrisma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as fs from 'fs';
import * as path from 'path';
import { promisify } from 'util';

const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);

const prismaInputFile = path.join(
process.cwd(),
'/src/adapters/prisma/lucia.prisma'
);

const prismaOutputFile = path.join(
process.cwd(),
'/src/adapters/lucia-prisma.ts'
);

async function copyPrismaFile() {
const prismaContent = await readFile(prismaInputFile);
const prismaOutputContent =
'/** auto generated code by "yarn generate" */\n' +
'export const luciaPrismaContent = `' +
prismaContent +
'`;\n';
await writeFile(prismaOutputFile, prismaOutputContent);
}

copyPrismaFile()
.then(() => {
console.log('copy prisma content to luciaPrisma.js success!');
})
.catch((err) => {
console.log('copy prisma content fail: ', err);
});
2 changes: 1 addition & 1 deletion packages/next-auth/flatjs-forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig({
},
entryPointOptions: {
libraries: {
importedLibraries: ['next', '@lucia-auth/oauth', 'lucia', 'zod'],
importedLibraries: ['next', 'zod'],
},
},
dtsFilter: (dtsFile) =>
Expand Down
15 changes: 9 additions & 6 deletions packages/next-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"package.json"
],
"scripts": {
"build": "flatjs-forge build -c",
"generate": "prisma generate --schema=./src/adapters/prisma/lucia.prisma && node copyPrisma.js",
"build": "yarn generate && flatjs-forge build -c",
"?build-release": "When https://github.com/atlassian/changesets/issues/432 has a solution we can remove this trick",
"build-release": "yarn build && rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
"clean": "rimraf --no-glob ./dist ./_release ./coverage ./tsconfig.tsbuildinfo",
Expand All @@ -46,20 +47,22 @@
"typecheck": "tsc --project ./tsconfig.json --noEmit"
},
"dependencies": {
"@lucia-auth/oauth": "^3.5.3",
"arctic": "1.8.1",
"oslo": "1.2.0",
"prisma": "5.13.0",
"zod": "^3.23.7"
},
"devDependencies": {
"@armit/eslint-config-bases": "^0.1.5",
"@flatjs/forge": "2.0.6",
"@flatjs/forge": "2.0.0",
"@types/node": "20.12.10",
"@vitest/coverage-istanbul": "1.6.0",
"@vitest/ui": "1.6.0",
"eslint": "8.55.0",
"lucia": "^2.x",
"next": "^14.2.3",
"npm-run-all": "4.1.5",
"prettier": "3.2.5",
"prisma": "^5.13.0",
"react": "^18.3.1",
"rimraf": "5.0.5",
"rollup-plugin-preserve-directives": "0.4.0",
Expand All @@ -70,8 +73,8 @@
"vitest": "1.6.0"
},
"peerDependencies": {
"lucia": "^2.x",
"next": "^14.2.3"
"next": "^14.2.3",
"react": "^18.3.1"
},
"engines": {
"node": ">=18.0.0"
Expand Down
2 changes: 2 additions & 0 deletions packages/next-auth/src/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './prisma-adapter.js';
export * from './lucia-prisma.js';
47 changes: 47 additions & 0 deletions packages/next-auth/src/adapters/lucia-prisma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/** auto generated code by "yarn generate" */
export const luciaPrismaContent = `datasource db {
provider = "sqlite"
url = "./prisma.db"
}

generator client {
provider = "prisma-client-js"
}

model User {
id String @id
username String @unique
email String? @unique
authSession Session[]
authorized Authorized[]

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model Authorized {
id String @id
userId String
hashedPassword String?
providerId String?
providerMethod String
user User @relation(references: [id], fields: [userId], onDelete: Cascade)

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@index([userId])
}

model Session {
id Int @id @default(autoincrement())
token String @unique
userId String
expiresAt DateTime @default(now())
user User @relation(references: [id], fields: [userId], onDelete: Cascade)

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@index([userId])
}`;
Loading
Loading