-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable features requiring authentication (#89)
Closes #81
- Loading branch information
Showing
22 changed files
with
246 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
NODE_ENV=development | ||
|
||
DEBUG="playnite-web/*" | ||
DEBUG="playnite-web-app/*" | ||
|
||
DB_HOST=localhost | ||
DB_PORT=27017 | ||
DB_USERNAME=local | ||
DB_PASSWORD=dev | ||
|
||
SECRET="some secret" | ||
USERNAME="username" | ||
PASSWORD="password" |
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
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,27 @@ | ||
import createDebugger from 'debug' | ||
import { Authenticator } from 'remix-auth' | ||
import { FormStrategy } from 'remix-auth-form' | ||
import { sessionStorage } from './session.server' | ||
|
||
const { USERNAME, PASSWORD } = process.env | ||
const debug = createDebugger('playnite-web-app/auth.server') | ||
|
||
const authenticator = new Authenticator<{ | ||
username: string | ||
}>(sessionStorage) | ||
|
||
authenticator.use( | ||
new FormStrategy(async ({ form }) => { | ||
let username = form.get('username') | ||
let password = form.get('password') | ||
if (USERNAME !== username || PASSWORD !== password) { | ||
debug('Invalid credentials', { username, password }) | ||
throw new Error('Invalid credentials') | ||
} | ||
|
||
return { username } | ||
}), | ||
'user-pass', | ||
) | ||
|
||
export { authenticator } |
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,16 @@ | ||
// app/services/session.server.ts | ||
import { createCookieSessionStorage } from '@remix-run/node' | ||
|
||
// export the whole sessionStorage object | ||
const sessionStorage = createCookieSessionStorage({ | ||
cookie: { | ||
name: '_session', // use any name you want here | ||
sameSite: 'strict', | ||
path: '/', | ||
httpOnly: true, | ||
secrets: [process.env.SECRET ?? 'secret'], | ||
secure: process.env.NODE_ENV === 'production', | ||
}, | ||
}) | ||
|
||
export { sessionStorage } |
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,28 @@ | ||
import { createSlice } from '@reduxjs/toolkit' | ||
import _ from 'lodash' | ||
|
||
const { merge } = _ | ||
|
||
const initialState = { | ||
isAuthenticated: false, | ||
} | ||
|
||
const authSlice = createSlice({ | ||
name: 'auth', | ||
initialState, | ||
selectors: { | ||
getIsAuthenticated: (state) => state.isAuthenticated, | ||
}, | ||
reducers: { | ||
signedIn(state, action) { | ||
return merge(state, { isAuthenticated: true }) | ||
}, | ||
signedOut(state, action) { | ||
return merge(state, { isAuthenticated: false }) | ||
}, | ||
}, | ||
}) | ||
|
||
export const { reducer } = authSlice | ||
export const { signedIn, signedOut } = authSlice.actions | ||
export const { getIsAuthenticated } = authSlice.selectors |
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,6 +1,10 @@ | ||
import { combineReducers } from '@reduxjs/toolkit' | ||
import * as authSlice from './authSlice' | ||
import * as layoutSlice from './layoutSlice' | ||
|
||
const reducer = combineReducers({ layout: layoutSlice.reducer }) | ||
const reducer = combineReducers({ | ||
layout: layoutSlice.reducer, | ||
auth: authSlice.reducer, | ||
}) | ||
|
||
export { reducer } |
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
File renamed without changes.
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
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.