-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/0.3.0' into main
- Loading branch information
Showing
47 changed files
with
2,384 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ yarn-error.log | |
|
||
# Platform specific | ||
.DS_Store | ||
/data/ |
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,23 @@ | ||
# Change Log | ||
|
||
## [UNRELEASED] | ||
|
||
## [0.3.0] - 2024-05-07 | ||
|
||
- Add `TailwindCSS` to the project. | ||
- Setup `Redis` to handle session storage. | ||
- Add `docker-compose.yaml` to the project to handle PostgreSQL and Redis in development environment. | ||
- Setup `OAuth2` authentication's controller and routes (Twitch for now). | ||
- Add i18n handling on frontend with `react-i18next`. | ||
- Setup default layout to pages. | ||
|
||
## [0.2.0] - 2024-05-01 | ||
|
||
### Added | ||
|
||
- ~~Add i18n handling to the project with `next-intl`.~~ | ||
- Switch project from `NextJS` to `AdonisJS`. | ||
|
||
## [0.1.1] - 2024-04-25 | ||
|
||
### Added |
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,50 @@ | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
import User from '#models/user' | ||
import Provider from '#models/provider' | ||
import { DateTime } from 'luxon' | ||
|
||
export default class AuthController { | ||
async redirect({ ally, params }: HttpContext) { | ||
const providerParams = params.provider | ||
const socialProvider = ally.use(providerParams) | ||
return await socialProvider.redirect() | ||
} | ||
|
||
async callback({ ally, auth, response, params, session }: HttpContext) { | ||
const providerParams = params.provider | ||
const socialProvider = ally.use(providerParams) | ||
|
||
if ( | ||
socialProvider.accessDenied() || | ||
socialProvider.stateMisMatch() || | ||
socialProvider.hasError() | ||
) { | ||
return response.redirect('/login') | ||
} | ||
|
||
const socialUser = await socialProvider.user() | ||
|
||
if (socialUser) { | ||
const provider = await Provider.findByOrFail('name', providerParams) | ||
await User.firstOrCreate( | ||
{ email: socialUser.email }, | ||
{ | ||
email: socialUser.email, | ||
username: socialUser.nickName, | ||
avatarUrl: socialUser.avatarUrl, | ||
providerId: provider.id, | ||
} | ||
) | ||
|
||
const user = await User.findByOrFail('email', socialUser.email) | ||
await auth.use('web').login(user) | ||
|
||
user.lastSessionId = session.sessionId | ||
user.lastSessionAt = DateTime.now() | ||
await user.save() | ||
|
||
return response.redirect('/') | ||
} | ||
return response.redirect('/') | ||
} | ||
} |
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 @@ | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
|
||
export default class HomeController { | ||
handle({ inertia }: HttpContext) { | ||
return inertia.render('home') | ||
} | ||
} |
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 @@ | ||
import type { HttpContext } from '@adonisjs/core/http' | ||
|
||
export default class LoginController { | ||
handle({ inertia }: HttpContext) { | ||
return inertia.render('login') | ||
} | ||
} |
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 |
---|---|---|
|
@@ -71,4 +71,4 @@ declare module '@adonisjs/core/http' { | |
export interface HttpContext { | ||
i18n: I18n | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -28,4 +28,4 @@ export default class GuestMiddleware { | |
|
||
return next() | ||
} | ||
} | ||
} |
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,19 @@ | ||
import type { DateTime } from 'luxon' | ||
import { BaseModel, column } from '@adonisjs/lucid/orm' | ||
import type { Opaque } from '@poppinss/utils/types' | ||
|
||
export type ProviderId = Opaque<number, 'ProviderId'> | ||
|
||
export default class Provider extends BaseModel { | ||
@column({ isPrimary: true }) | ||
declare id: ProviderId | ||
|
||
@column() | ||
declare name: string | ||
|
||
@column.dateTime({ autoCreate: true }) | ||
declare createdAt: DateTime | ||
|
||
@column.dateTime({ autoCreate: true, autoUpdate: true }) | ||
declare updatedAt: DateTime | ||
} |
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,30 +1,48 @@ | ||
import { DateTime } from 'luxon' | ||
import type { DateTime } from 'luxon' | ||
import hash from '@adonisjs/core/services/hash' | ||
import { compose } from '@adonisjs/core/helpers' | ||
import { BaseModel, column } from '@adonisjs/lucid/orm' | ||
import { withAuthFinder } from '@adonisjs/auth/mixins/lucid' | ||
import type { Opaque } from '@poppinss/utils/types' | ||
|
||
const AuthFinder = withAuthFinder(() => hash.use('scrypt'), { | ||
uids: ['email'], | ||
uids: ['username', 'email'], | ||
passwordColumnName: 'password', | ||
}) | ||
|
||
export type UserId = Opaque<string, 'UserId'> | ||
|
||
export default class User extends compose(BaseModel, AuthFinder) { | ||
@column({ isPrimary: true }) | ||
declare id: number | ||
declare id: UserId | ||
|
||
@column() | ||
declare fullName: string | null | ||
declare username: string | ||
|
||
@column() | ||
declare email: string | ||
|
||
@column() | ||
declare password: string | ||
declare emailVerifiedAt: DateTime | null | ||
|
||
@column() | ||
declare avatarUrl: string | null | ||
|
||
@column() | ||
declare providerId: number | ||
|
||
@column() | ||
declare password: string | null | ||
|
||
@column() | ||
declare lastSessionId: string | null | ||
|
||
@column() | ||
declare lastSessionAt: DateTime | null | ||
|
||
@column.dateTime({ autoCreate: true }) | ||
declare createdAt: DateTime | ||
|
||
@column.dateTime({ autoCreate: true, autoUpdate: true }) | ||
declare updatedAt: DateTime | null | ||
} | ||
} |
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,17 @@ | ||
import env from '#start/env' | ||
import { defineConfig } from '@adonisjs/ally' | ||
import { twitch } from '@rlanz/ally-twitch' | ||
|
||
const allyConfig = defineConfig({ | ||
twitch: twitch({ | ||
clientId: env.get('TWITCH_CLIENT_ID'), | ||
clientSecret: env.get('TWITCH_CLIENT_SECRET'), | ||
callbackUrl: env.get('TWITCH_CALLBACK_URL'), | ||
}), | ||
}) | ||
|
||
export default allyConfig | ||
|
||
declare module '@adonisjs/ally/types' { | ||
interface SocialProviders extends InferSocialProviders<typeof allyConfig> {} | ||
} |
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 |
---|---|---|
|
@@ -21,4 +21,4 @@ const dbConfig = defineConfig({ | |
}, | ||
}) | ||
|
||
export default dbConfig | ||
export default dbConfig |
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,36 @@ | ||
import env from '#start/env' | ||
import { defineConfig } from '@adonisjs/redis' | ||
import { InferConnections } from '@adonisjs/redis/types' | ||
|
||
const redisConfig = defineConfig({ | ||
connection: 'main', | ||
|
||
connections: { | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| The default connection | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The main connection you want to use to execute redis commands. The same | ||
| connection will be used by the session provider, if you rely on the | ||
| redis driver. | ||
| | ||
*/ | ||
main: { | ||
host: env.get('REDIS_HOST'), | ||
port: env.get('REDIS_PORT'), | ||
password: env.get('REDIS_PASSWORD', ''), | ||
db: 0, | ||
keyPrefix: '', | ||
retryStrategy(times) { | ||
return times > 10 ? null : times * 50 | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
export default redisConfig | ||
|
||
declare module '@adonisjs/redis/types' { | ||
export interface RedisConnections extends InferConnections<typeof redisConfig> {} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
database/migrations/1714403715625_create_providers_table.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,31 @@ | ||
import { BaseSchema } from '@adonisjs/lucid/schema' | ||
import { DateTime } from 'luxon' | ||
|
||
export default class extends BaseSchema { | ||
protected tableName = 'providers' | ||
|
||
async up() { | ||
this.schema.createTable(this.tableName, (table) => { | ||
table.increments('id') | ||
table.string('name').unique().notNullable() | ||
table.timestamp('created_at', { useTz: true }) | ||
table.timestamp('updated_at', { useTz: true }) | ||
}) | ||
|
||
const providers = ['twitch', 'youtube', 'kick', 'discord'] | ||
|
||
this.defer(async () => { | ||
for (const provider of providers) { | ||
await this.db.insertQuery().table(this.tableName).insert({ | ||
name: provider, | ||
created_at: DateTime.now(), | ||
updated_at: DateTime.now(), | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
async down() { | ||
this.schema.dropTable(this.tableName) | ||
} | ||
} |
Oops, something went wrong.