Skip to content

Commit 83c8146

Browse files
committed
Merge branch 'release/0.3.0' into main
2 parents c31a8f0 + 3a34735 commit 83c8146

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2384
-157
lines changed

.env.example

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ HOST=localhost
44
LOG_LEVEL=info
55
APP_KEY=lTtQy5-Mp2Vl-lhSrc92tBLhWitA7JK8
66
NODE_ENV=development
7+
78
SESSION_DRIVER=cookie
9+
810
DB_HOST=127.0.0.1
911
DB_PORT=5432
1012
DB_USER=postgres
1113
DB_PASSWORD=
12-
DB_DATABASE=
14+
DB_DATABASE=
15+
16+
REDIS_PASSWORD=
17+
REDIS_HOST=127.0.0.1
18+
REDIS_PORT=6379
19+
20+
TWITCH_CLIENT_ID=
21+
TWITCH_CLIENT_SECRET=
22+
TWITCH_CALLBACK_URL=

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ yarn-error.log
2323

2424
# Platform specific
2525
.DS_Store
26+
/data/

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
# Change Log
22

3+
## [UNRELEASED]
4+
5+
## [0.3.0] - 2024-05-07
6+
7+
- Add `TailwindCSS` to the project.
8+
- Setup `Redis` to handle session storage.
9+
- Add `docker-compose.yaml` to the project to handle PostgreSQL and Redis in development environment.
10+
- Setup `OAuth2` authentication's controller and routes (Twitch for now).
11+
- Add i18n handling on frontend with `react-i18next`.
12+
- Setup default layout to pages.
13+
314
## [0.2.0] - 2024-05-01
15+
416
### Added
17+
518
- ~~Add i18n handling to the project with `next-intl`.~~
619
- Switch project from `NextJS` to `AdonisJS`.
720

821
## [0.1.1] - 2024-04-25
22+
923
### Added

adonisrc.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export default defineConfig({
3838
() => import('@adonisjs/lucid/database_provider'),
3939
() => import('@adonisjs/auth/auth_provider'),
4040
() => import('@adonisjs/inertia/inertia_provider'),
41-
() => import('@adonisjs/i18n/i18n_provider')
41+
() => import('@adonisjs/i18n/i18n_provider'),
42+
() => import('@adonisjs/redis/redis_provider'),
43+
() => import('@adonisjs/ally/ally_provider')
4244
],
4345

4446
/*
@@ -97,7 +99,7 @@ export default defineConfig({
9799
{
98100
pattern: 'resources/lang/**/*.{json,yaml,yml}',
99101
reloadServer: false,
100-
}
102+
},
101103
],
102104

103105
assetsBundler: false,

app/controllers/auth_controller.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import type { HttpContext } from '@adonisjs/core/http'
2+
import User from '#models/user'
3+
import Provider from '#models/provider'
4+
import { DateTime } from 'luxon'
5+
6+
export default class AuthController {
7+
async redirect({ ally, params }: HttpContext) {
8+
const providerParams = params.provider
9+
const socialProvider = ally.use(providerParams)
10+
return await socialProvider.redirect()
11+
}
12+
13+
async callback({ ally, auth, response, params, session }: HttpContext) {
14+
const providerParams = params.provider
15+
const socialProvider = ally.use(providerParams)
16+
17+
if (
18+
socialProvider.accessDenied() ||
19+
socialProvider.stateMisMatch() ||
20+
socialProvider.hasError()
21+
) {
22+
return response.redirect('/login')
23+
}
24+
25+
const socialUser = await socialProvider.user()
26+
27+
if (socialUser) {
28+
const provider = await Provider.findByOrFail('name', providerParams)
29+
await User.firstOrCreate(
30+
{ email: socialUser.email },
31+
{
32+
email: socialUser.email,
33+
username: socialUser.nickName,
34+
avatarUrl: socialUser.avatarUrl,
35+
providerId: provider.id,
36+
}
37+
)
38+
39+
const user = await User.findByOrFail('email', socialUser.email)
40+
await auth.use('web').login(user)
41+
42+
user.lastSessionId = session.sessionId
43+
user.lastSessionAt = DateTime.now()
44+
await user.save()
45+
46+
return response.redirect('/')
47+
}
48+
return response.redirect('/')
49+
}
50+
}

app/controllers/home_controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { HttpContext } from '@adonisjs/core/http'
2+
3+
export default class HomeController {
4+
handle({ inertia }: HttpContext) {
5+
return inertia.render('home')
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { HttpContext } from '@adonisjs/core/http'
2+
3+
export default class LoginController {
4+
handle({ inertia }: HttpContext) {
5+
return inertia.render('login')
6+
}
7+
}

app/middleware/auth_middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ export default class AuthMiddleware {
2222
await ctx.auth.authenticateUsing(options.guards, { loginRoute: this.redirectTo })
2323
return next()
2424
}
25-
}
25+
}

app/middleware/detect_user_locale_middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ declare module '@adonisjs/core/http' {
7171
export interface HttpContext {
7272
i18n: I18n
7373
}
74-
}
74+
}

app/middleware/guest_middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ export default class GuestMiddleware {
2828

2929
return next()
3030
}
31-
}
31+
}

0 commit comments

Comments
 (0)