Skip to content
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
12 changes: 12 additions & 0 deletions examples/supertokens-migration/backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SUPERTOKENS_CONNECTION_URI=http://localhost:3567
# SUPERTOKENS_API_KEY=your_core_api_key # only needed if you set one in supertokens-core

ROWND_APP_KEY=your_rownd_app_key
ROWND_APP_SECRET=your_rownd_app_secret

PORT=3001

# Origin of the Rownd Hub iframe — migration fetches come from here, not from
# the host app. Use http://localhost:8787 when running the Hub dev server
# locally, or https://hub.rownd.io for production.
HUB_ORIGIN=http://localhost:8787
1 change: 1 addition & 0 deletions examples/supertokens-migration/backend/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install-links=true
23 changes: 23 additions & 0 deletions examples/supertokens-migration/backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "user-migration-backend",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "tsx watch src/index.ts",
"start": "tsx src/index.ts"
},
"dependencies": {
"@supertokens-plugins/rownd-nodejs": "latest",
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"express": "^4.18.0",
"supertokens-node": "^23.0.0"
},
"devDependencies": {
"@types/cors": "^2.8.13",
"@types/express": "^4.17.21",
"@types/node": "^20.0.0",
"tsx": "^4.0.0",
"typescript": "^5.0.0"
}
}
88 changes: 88 additions & 0 deletions examples/supertokens-migration/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import 'dotenv/config';
import express from 'express';
import cors from 'cors';
import supertokens from 'supertokens-node';
import Session from 'supertokens-node/recipe/session';
import Passwordless from 'supertokens-node/recipe/passwordless';
import UserMetadata from 'supertokens-node/recipe/usermetadata';
import AccountLinking from 'supertokens-node/recipe/accountlinking';
import { middleware, errorHandler } from 'supertokens-node/framework/express';
import RowndPlugin from '@supertokens-plugins/rownd-nodejs';

const PORT = Number(process.env.PORT) || 3001;

const WEBSITE_ORIGIN = process.env.WEBSITE_ORIGIN || 'http://localhost:5173';
const HUB_ORIGIN = process.env.HUB_ORIGIN || 'http://localhost:8787';

const ALLOWED_ORIGINS = [WEBSITE_ORIGIN, HUB_ORIGIN];

supertokens.init({
framework: 'express',
supertokens: {
connectionURI:
process.env.SUPERTOKENS_CONNECTION_URI || 'http://localhost:3567',
apiKey: process.env.SUPERTOKENS_API_KEY,
},
appInfo: {
appName: 'User Migration Example',
apiDomain: `http://localhost:${PORT}`,
websiteDomain: WEBSITE_ORIGIN,
apiBasePath: '/auth',
websiteBasePath: '/auth',
},
recipeList: [
Passwordless.init({
contactMethod: 'EMAIL_OR_PHONE',
flowType: 'USER_INPUT_CODE',
}),
Session.init({
tokenTransferMethod: 'header',
}),
UserMetadata.init(),
AccountLinking.init({
shouldDoAutomaticAccountLinking: async () => ({
shouldAutomaticallyLink: true,
shouldRequireVerification: false,
}),
}),
],
experimental: {
plugins: [
RowndPlugin.init({
rowndAppKey: process.env.ROWND_APP_KEY!,
rowndAppSecret: process.env.ROWND_APP_SECRET!,
enableDebugLogs: true,
}),
],
},
});

const app = express();

app.use(
cors({
origin: ALLOWED_ORIGINS,
allowedHeaders: ['content-type', ...supertokens.getAllCORSHeaders()],
credentials: true,
})
);

app.use(express.json());

app.use((req, _res, next) => {
console.log(
`[${new Date().toISOString()}] ${req.method} ${req.url} (origin: ${req.headers.origin ?? 'none'})`
);
next();
});

app.use(middleware());

app.use(errorHandler());

app.listen(PORT, () => {
console.log(`Backend running on http://localhost:${PORT}`);
console.log(
`SuperTokens Core: ${process.env.SUPERTOKENS_CONNECTION_URI || 'http://localhost:3567'}`
);
});
12 changes: 12 additions & 0 deletions examples/supertokens-migration/backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist"
},
"include": ["src"]
}
12 changes: 12 additions & 0 deletions examples/supertokens-migration/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>User Migration Example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading