-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ft send verification email 187584913 (#30)
* [finishes #187584913] finished sending verification email features * [finishes #187584913] finished sending verification email features
- Loading branch information
AimePazzo
authored
May 28, 2024
1 parent
15533e4
commit 80e32f4
Showing
19 changed files
with
622 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"check-coverage": true, | ||
"lines": 80, | ||
"functions": 80, | ||
"branches": 80, | ||
"statements": 80 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/databases/migrations/20240523180022-create-sessions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { QueryInterface, DataTypes } from "sequelize"; | ||
export default { | ||
up: async (queryInterface: QueryInterface) => { | ||
await queryInterface.createTable("sessions", { | ||
id: { | ||
type: DataTypes.INTEGER, | ||
autoIncrement: true, | ||
primaryKey: true | ||
}, | ||
userId: { | ||
type: new DataTypes.INTEGER, | ||
allowNull: false | ||
}, | ||
device: { | ||
type: new DataTypes.STRING(280), | ||
allowNull: true | ||
}, | ||
token: { | ||
type: new DataTypes.STRING(280), | ||
allowNull: true | ||
}, | ||
otp: { | ||
type: new DataTypes.STRING(280), | ||
allowNull: true | ||
}, | ||
createdAt: { | ||
field: "createdAt", | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW | ||
}, | ||
updatedAt: { | ||
field: "updatedAt", | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW | ||
} | ||
}); | ||
}, | ||
|
||
down: async (queryInterface: QueryInterface) => { | ||
await queryInterface.dropTable("sessions"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable require-jsdoc */ | ||
import { Model, DataTypes } from "sequelize"; | ||
import sequelizeConnection from "../config/db.config"; | ||
export interface SessionAttributes { | ||
id: number; | ||
userId: number; | ||
device: string; | ||
token: string; | ||
otp: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} | ||
|
||
class Session extends Model<SessionAttributes> implements SessionAttributes { | ||
declare id: number; | ||
declare userId: number; | ||
declare device: string; | ||
declare token: string; | ||
declare otp:string; | ||
declare createdAt: Date; | ||
declare updatedAt: Date; | ||
|
||
static associate(models: any) { | ||
Session.belongsTo(models.Users, { foreignKey: "userId",as: "user" }); | ||
} | ||
} | ||
|
||
Session.init( | ||
{ | ||
id: { | ||
type: DataTypes.INTEGER, | ||
autoIncrement: true, | ||
primaryKey: true | ||
}, | ||
userId: { | ||
type: new DataTypes.INTEGER, | ||
allowNull: false | ||
}, | ||
device: { | ||
type: new DataTypes.STRING(280), | ||
allowNull: true | ||
}, | ||
token: { | ||
type: new DataTypes.STRING(280), | ||
allowNull: true | ||
}, | ||
otp: { | ||
type: new DataTypes.STRING(280), | ||
allowNull: true | ||
}, | ||
createdAt: { | ||
field: "createdAt", | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW | ||
}, | ||
updatedAt: { | ||
field: "updatedAt", | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW | ||
} | ||
}, | ||
{ | ||
sequelize: sequelizeConnection, | ||
tableName: "sessions", | ||
timestamps: true, | ||
modelName:"Sessions" | ||
} | ||
); | ||
|
||
export default Session; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import jwt from "jsonwebtoken" | ||
import jwt,{JwtPayload} from "jsonwebtoken" | ||
import dotenv from "dotenv" | ||
|
||
dotenv.config | ||
|
||
const generateToken = (id: number) => { | ||
return jwt.sign({ id }, process.env.JWT_SECRET, { expiresIn: "1h" }); | ||
}; | ||
export { generateToken} | ||
|
||
const decodeToken = (token: string) => { | ||
return jwt.verify(token, process.env.JWT_SECRET) as JwtPayload | ||
; | ||
}; | ||
|
||
export { generateToken, decodeToken} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.