Skip to content

Commit

Permalink
feat(web): implement user authentication and add on the fly migration…
Browse files Browse the repository at this point in the history
… to Strapi's authentication
  • Loading branch information
izzyyhh committed May 7, 2024
1 parent 4d3eaea commit 2ff10a6
Show file tree
Hide file tree
Showing 15 changed files with 325 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DATABASE_PASSWORD=super-secret
DATABASE_PORT=3306
DATABASE_SSL=false

APP_DATABASE_NAME=vim
WEB_DATABASE_NAME=vim
CMS_DATABASE_NAME=vim_cms

CMS_PORT=1337
Expand Down
3 changes: 0 additions & 3 deletions cms/src/extensions/users-permissions/strapi-server.ts

This file was deleted.

15 changes: 3 additions & 12 deletions scripts/user-migration/user-migration.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
// example migration
const strapiUrl = "http://localhost:1337/api";

const axios = require("axios");

async function getUsersFromStrapi() {
try {
// Make a GET request to the Strapi API to fetch users
const response = await axios.get(`${strapiUrl}/users`);

// Extract user data from the response
const users = response.data;

// Output user data
console.log("Users:");
console.log(users);
} catch (error) {
console.error("Error fetching users:", error.message);
Expand Down Expand Up @@ -43,19 +37,16 @@ async function createUser(username, email, password, old_password) {
}
}

// Get the client
const mysql = require("mysql2");
// Create the connection to database
const connection = mysql.createConnection({
host: "localhost",
user: "vim",
database: "vim",
password: "super-secret",
});

// A simple SELECT query
connection.query("SELECT * FROM `vs_users`", function (err, results, fields) {
console.log(results); // results contains rows returned by server
console.log(results);

results.forEach((user) => {
createUser(user.user_name, user.email, "123gege321", "old_hash")
Expand All @@ -67,5 +58,5 @@ connection.query("SELECT * FROM `vs_users`", function (err, results, fields) {
});
});

console.log(fields); // fields contains extra meta data about results, if available
console.log(fields);
});
140 changes: 140 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"@tabler/icons-react": "^2.45.0",
"@tanstack/react-table": "^8.11.7",
"axios": "^1.6.8",
"md5": "^2.3.0",
"mysql2": "^3.9.7",
"next": "13.5.6",
"next-auth": "^4.24.7",
"qs": "^6.11.2",
Expand All @@ -23,6 +25,7 @@
"swiper": "^11.0.5"
},
"devDependencies": {
"@types/md5": "^2.3.5",
"@types/node": "^20",
"@types/qs": "^6.9.11",
"@types/react": "^18",
Expand Down
Loading

0 comments on commit 2ff10a6

Please sign in to comment.