-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cms): fix user registration endpoints & add generateOrmTypes com…
…mand to create-tensei-app
- Loading branch information
Showing
9 changed files
with
247 additions
and
29 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
11 changes: 11 additions & 0 deletions
11
packages/cms/pages/components/auth/context/auth-context.tsx
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,11 @@ | ||
import { TenseiCtxInterface } from '@tensei/components' | ||
import { createContext } from 'react' | ||
|
||
export const TenseiCtx = createContext<TenseiCtxInterface>({ | ||
user: null as any, | ||
booted: false, | ||
setUser: () => {}, | ||
setBooted: () => {}, | ||
routes: [], | ||
setRoutes: () => {} | ||
}) |
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 @@ | ||
export { TenseiCtx } from './auth-context' |
28 changes: 28 additions & 0 deletions
28
packages/cms/pages/components/auth/guards/must-be-authenticated.tsx
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 React from 'react' | ||
import { Redirect } from 'react-router-dom' | ||
|
||
import { TenseiCtx } from '../context' | ||
|
||
export const MustBeAuthComponent = (Component: React.FC) => { | ||
const Comp = (props: any) => { | ||
return ( | ||
<TenseiCtx.Consumer> | ||
{({ user }) => | ||
user ? ( | ||
<Component {...props} /> | ||
) : ( | ||
<Redirect | ||
to={ | ||
window.Tensei.state.registered | ||
? window.Tensei.getPath('auth/login') | ||
: window.Tensei.getPath('auth/register') | ||
} | ||
/> | ||
) | ||
} | ||
</TenseiCtx.Consumer> | ||
) | ||
} | ||
|
||
return Comp | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/cms/pages/components/auth/guards/must-not-be-authenticated.tsx
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,22 @@ | ||
import React from 'react' | ||
import { Redirect } from 'react-router-dom' | ||
|
||
import { TenseiCtx } from '../context' | ||
|
||
export const MustBeNotAuthComponent = (Component: React.FC) => { | ||
const Comp = (props: any) => { | ||
return ( | ||
<TenseiCtx.Consumer> | ||
{({ user }) => | ||
!user ? ( | ||
<Component {...props} /> | ||
) : ( | ||
<Redirect to={window.Tensei.getPath('')} /> | ||
) | ||
} | ||
</TenseiCtx.Consumer> | ||
) | ||
} | ||
|
||
return Comp | ||
} |
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
18 changes: 18 additions & 0 deletions
18
packages/create-tensei-app/tasks/generate-orm-types/index.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,18 @@ | ||
import execa from 'execa' | ||
import { TaskFn } from '../../contracts' | ||
import { getInstallMessage } from '../../helpers' | ||
import { packages } from '../../schematics/packages' | ||
|
||
/** | ||
* Runs the tensei orm:types command after installation and setup. | ||
*/ | ||
const task: TaskFn = async (_, logger, { absPath, debug }) => { | ||
try { | ||
await execa('npm', ['run', 'postinstall'], { | ||
cwd: absPath, | ||
...(debug ? { stdio: 'inherit' } : {}) | ||
}) | ||
} catch {} | ||
} | ||
|
||
export default task |
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