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

User authentication #24

Merged
merged 15 commits into from
May 8, 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
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"kind": "collectionType",
"collectionName": "up_users",
"info": {
"name": "user",
"description": "",
"singularName": "user",
"pluralName": "users",
"displayName": "User"
},
"options": {
"draftAndPublish": false
},
"attributes": {
"username": {
"type": "string",
"minLength": 3,
"unique": true,
"configurable": false,
"required": true
},
"email": {
"type": "email",
"minLength": 6,
"configurable": false,
"required": true
},
"provider": {
"type": "string",
"configurable": false
},
"password": {
"type": "password",
"minLength": 6,
"configurable": false,
"private": true,
"searchable": false
},
"resetPasswordToken": {
"type": "string",
"configurable": false,
"private": true,
"searchable": false
},
"confirmationToken": {
"type": "string",
"configurable": false,
"private": true,
"searchable": false
},
"confirmed": {
"type": "boolean",
"default": false,
"configurable": false
},
"blocked": {
"type": "boolean",
"default": false,
"configurable": false
},
"role": {
"type": "relation",
"relation": "manyToOne",
"target": "plugin::users-permissions.role",
"inversedBy": "users",
"configurable": false
},
"old_pw_hash": {
"type": "string"
},
"migrated_pw": {
"type": "boolean",
"default": false
}
}
}
207 changes: 207 additions & 0 deletions scripts/user-migration/package-lock.json

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

15 changes: 15 additions & 0 deletions scripts/user-migration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "user-migration",
"version": "1.0.0",
"description": "",
"main": "user-migration.js",
"scripts": {
"migrate": "node user-migration.js"
},
"author": "izzy",
"license": "ISC",
"dependencies": {
"axios": "^1.6.8",
"mysql2": "^3.9.3"
}
}
62 changes: 62 additions & 0 deletions scripts/user-migration/user-migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// example migration
const strapiUrl = "http://localhost:1337/api";
const axios = require("axios");

async function getUsersFromStrapi() {
try {
const response = await axios.get(`${strapiUrl}/users`);
const users = response.data;
console.log(users);
} catch (error) {
console.error("Error fetching users:", error.message);
}
}

async function createUser(username, email, password, old_password) {
try {
const response = await fetch(`${strapiUrl}/auth/local/register`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
username: username,
email: email,
password: password,
old_pw_hash: old_password,
}),
});
console.log(response);

return await response.json();
} catch (e) {
console.log("something went wrong");
console.log(e);
return null;
}
}

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

connection.query("SELECT * FROM `vs_users`", function (err, results, fields) {
console.log(results);

results.forEach((user) => {
createUser(user.user_name, user.email, "123gege321", "old_hash")
.then((a) => {
console.log(a);
})
.catch((err) => {
console.log(err);
});
});

console.log(fields);
});
1 change: 1 addition & 0 deletions web/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY next.config.js .
COPY tsconfig.json .
COPY postcss.config.js .
COPY tailwind.config.ts .
COPY .env .

ENV NEXT_TELEMETRY_DISABLED 1

Expand Down
Loading
Loading