auth send link common mutation
This commit is contained in:
parent
90cfa1f128
commit
9f03a0e5cc
|
@ -1,9 +0,0 @@
|
|||
git filter-branch --tag-name-filter 'cat' -f --tree-filter '
|
||||
find . -type d -name binarydir | while read dir
|
||||
do
|
||||
find $dir -type f -name "*.ear" -o -name "*.war" -o -name "*.jar" -o -name "*.zip" -o -name "*.exe" | while read file
|
||||
do
|
||||
git rm -r -f --ignore-unmatch $file
|
||||
done
|
||||
done
|
||||
' -- --all
|
|
@ -8,8 +8,8 @@ import { useArticlesStore, loadSearchResults } from '../../stores/zine/articles'
|
|||
import { useStore } from '@nanostores/solid'
|
||||
|
||||
type Props = {
|
||||
query: string
|
||||
results: Shout[]
|
||||
query?: string
|
||||
results?: Shout[]
|
||||
}
|
||||
|
||||
export const SearchPage = (props: Props) => {
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
import { ClientOptions, dedupExchange, fetchExchange, createClient, Exchange } from '@urql/core'
|
||||
import { devtoolsExchange } from '@urql/devtools'
|
||||
|
||||
// FIXME actual value
|
||||
const isDev = true
|
||||
|
||||
// export const baseUrl = 'https://.discours.io'
|
||||
export const baseUrl = 'http://localhost:8000'
|
||||
|
||||
const exchanges: Exchange[] = [dedupExchange, fetchExchange]
|
||||
|
||||
if (isDev) {
|
||||
exchanges.unshift(devtoolsExchange)
|
||||
}
|
||||
|
||||
const options: ClientOptions = {
|
||||
url: baseUrl,
|
||||
maskTypename: true,
|
||||
requestPolicy: 'cache-and-network',
|
||||
exchanges
|
||||
}
|
||||
|
||||
export const publicGraphQLClient = createClient(options)
|
|
@ -2,7 +2,7 @@
|
|||
import signIn from './query/auth-login'
|
||||
import signUp from './mutation/auth-register'
|
||||
import signOut from './mutation/auth-logout'
|
||||
import checkEmail from './query/auth-check'
|
||||
import checkEmail from './query/auth-check-email'
|
||||
import getSession from './mutation/my-session'
|
||||
// articles
|
||||
import topOverall from './query/articles-top-rated'
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { gql } from '@urql/core'
|
||||
|
||||
export default gql`
|
||||
query ForgetQuery($email: String!) {
|
||||
forget(email: $email) {
|
||||
query ConfirmEmailQuery($code: String!) {
|
||||
confirmEmail(code: $code) {
|
||||
error
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
import { gql } from '@urql/core'
|
||||
|
||||
export default gql`
|
||||
query ResendQuery($email: String!) {
|
||||
resend(email: $email) {
|
||||
error
|
||||
}
|
||||
}
|
||||
`
|
|
@ -1,8 +1,8 @@
|
|||
import { gql } from '@urql/core'
|
||||
|
||||
export default gql`
|
||||
query ResetQuery($code: String!) {
|
||||
reset(code: $code) {
|
||||
query SendLinkQuery($email: String!) {
|
||||
sendLink(email: $email) {
|
||||
error
|
||||
}
|
||||
}
|
|
@ -4,8 +4,8 @@ import { devtoolsExchange } from '@urql/devtools'
|
|||
// FIXME actual value
|
||||
const isDev = true
|
||||
|
||||
export const baseUrl = 'https://newapi.discours.io'
|
||||
//export const baseUrl = 'http://localhost:8000'
|
||||
//export const baseUrl = 'https://newapi.discours.io'
|
||||
export const baseUrl = 'http://localhost:8000'
|
||||
|
||||
const exchanges: Exchange[] = [dedupExchange, fetchExchange]
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { gql } from '@urql/core'
|
||||
|
||||
export default gql`
|
||||
query ReactionsByShoutQuery($limit: String!, $limit: Int!, $offset: Int!) {
|
||||
query ReactionsByShoutQuery($slug: String!, $limit: String!, $limit: Int!, $offset: Int!) {
|
||||
reactionsByShout(slug: $slug, limit: $limit, offset: $offset) {
|
||||
id
|
||||
body
|
||||
|
|
|
@ -5,17 +5,13 @@ import { Header } from '../components/Nav/Header'
|
|||
import { Footer } from '../components/Discours/Footer'
|
||||
import { ServerRouterProvider } from '../components/providers/ServerRouterProvider'
|
||||
import { t } from '../utils/intl'
|
||||
import { locale as langstore } from '../stores/ui'
|
||||
import { useStore } from '@nanostores/solid'
|
||||
|
||||
const { pathname, search } = Astro.url
|
||||
|
||||
// FIXME always returns ru
|
||||
const locale = useStore(langstore)
|
||||
const lang = Astro.url.searchParams['lang']
|
||||
---
|
||||
|
||||
<ServerRouterProvider href={pathname + search}>
|
||||
<html lang={locale() || 'en'}>
|
||||
<html lang={lang || 'en'}>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { atom, action } from 'nanostores'
|
||||
import { atom } from 'nanostores'
|
||||
import type { AuthResult } from '../graphql/types.gen'
|
||||
import { getLogger } from '../utils/logger'
|
||||
import { resetToken, setToken } from '../graphql/privateGraphQLClient'
|
||||
|
@ -9,14 +9,14 @@ const log = getLogger('auth-store')
|
|||
export const session = atom<AuthResult>()
|
||||
|
||||
export const signIn = async (params) => {
|
||||
const s = await apiClient.signIn(params)
|
||||
const s = await apiClient.authLogin(params)
|
||||
session.set(s)
|
||||
setToken(s.token)
|
||||
log.debug('signed in')
|
||||
}
|
||||
|
||||
export const signUp = async (params) => {
|
||||
const s = await apiClient.signUp(params)
|
||||
const s = await apiClient.authRegiser(params)
|
||||
session.set(s)
|
||||
setToken(s.token)
|
||||
log.debug('signed up')
|
||||
|
@ -31,22 +31,18 @@ export const signOut = () => {
|
|||
export const emailChecks = atom<{ [email: string]: boolean }>({})
|
||||
|
||||
export const signCheck = async (params) => {
|
||||
emailChecks.set(await apiClient.signCheck(params))
|
||||
emailChecks.set(await apiClient.authCheckEmail(params))
|
||||
}
|
||||
|
||||
export const resetCode = atom<string>()
|
||||
|
||||
export const signReset = async (params) => {
|
||||
await apiClient.signReset(params) // { email }
|
||||
export const signSendLink = async (params) => {
|
||||
await apiClient.authSendLink(params) // { email }
|
||||
resetToken()
|
||||
}
|
||||
|
||||
export const signResend = async (params) => {
|
||||
await apiClient.signResend(params) // { email }
|
||||
}
|
||||
|
||||
export const signResetConfirm = async (params) => {
|
||||
const auth = await apiClient.signResetConfirm(params) // { code }
|
||||
export const signConfirm = async (params) => {
|
||||
const auth = await apiClient.authConfirmCode(params) // { code }
|
||||
setToken(auth.token)
|
||||
session.set(auth)
|
||||
}
|
||||
|
|
|
@ -105,7 +105,6 @@ type InitialState = {
|
|||
}
|
||||
|
||||
export const useTopicsStore = ({ topics, randomTopics }: InitialState = {}) => {
|
||||
// console.log('using topics store')
|
||||
if (topics) {
|
||||
addTopics(topics)
|
||||
}
|
||||
|
@ -114,7 +113,6 @@ export const useTopicsStore = ({ topics, randomTopics }: InitialState = {}) => {
|
|||
}
|
||||
if (!randomTopicsStore) {
|
||||
randomTopicsStore = atom(randomTopics)
|
||||
// console.log('random topics separate store')
|
||||
}
|
||||
|
||||
const getTopicEntities = useStore(topicEntitiesStore)
|
||||
|
|
|
@ -10,9 +10,12 @@ import { getLogger } from './logger'
|
|||
import reactionsForShouts from '../graphql/query/reactions-for-shouts'
|
||||
import mySession from '../graphql/mutation/my-session'
|
||||
import { privateGraphQLClient } from '../graphql/privateGraphQLClient'
|
||||
import authLogout from '../graphql/mutation/auth-logout'
|
||||
import authLogin from '../graphql/query/auth-login'
|
||||
import authRegister from '../graphql/mutation/auth-register'
|
||||
import authLogoutQuery from '../graphql/mutation/auth-logout'
|
||||
import authLoginQuery from '../graphql/query/auth-login'
|
||||
import authRegisterMutation from '../graphql/mutation/auth-register'
|
||||
import authCheckEmailQuery from '../graphql/query/auth-check-email'
|
||||
import authConfirmCodeMutation from '../graphql/mutation/auth-confirm-email'
|
||||
import authSendLinkMutation from '../graphql/mutation/auth-send-link'
|
||||
import followMutation from '../graphql/mutation/follow'
|
||||
import unfollowMutation from '../graphql/mutation/unfollow'
|
||||
import articlesForAuthors from '../graphql/query/articles-for-authors'
|
||||
|
@ -25,10 +28,6 @@ import authorsAll from '../graphql/query/authors-all'
|
|||
import reactionCreate from '../graphql/mutation/reaction-create'
|
||||
import reactionDestroy from '../graphql/mutation/reaction-destroy'
|
||||
import reactionUpdate from '../graphql/mutation/reaction-update'
|
||||
import authCheck from '../graphql/query/auth-check'
|
||||
import authReset from '../graphql/mutation/auth-reset'
|
||||
import authForget from '../graphql/mutation/auth-forget'
|
||||
import authResend from '../graphql/mutation/auth-resend'
|
||||
import authorsBySlugs from '../graphql/query/authors-by-slugs'
|
||||
import incrementView from '../graphql/mutation/increment-view'
|
||||
|
||||
|
@ -39,6 +38,36 @@ const REACTIONS_PAGE_SIZE = 100
|
|||
const DEFAULT_RANDOM_TOPICS_AMOUNT = 12
|
||||
|
||||
export const apiClient = {
|
||||
// auth
|
||||
|
||||
authLogin: async ({ email, password }) => {
|
||||
const response = await publicGraphQLClient.query(authLoginQuery, { email, password }).toPromise()
|
||||
return response.data.signIn
|
||||
},
|
||||
authRegiser: async ({ email, password }) => {
|
||||
const response = await publicGraphQLClient.query(authRegisterMutation, { email, password }).toPromise()
|
||||
return response.data.registerUser
|
||||
},
|
||||
authSignOut: async () => {
|
||||
const response = await publicGraphQLClient.query(authLogoutQuery, {}).toPromise()
|
||||
return response.data.signOut
|
||||
},
|
||||
authCheckEmail: async ({ email }) => {
|
||||
// check if email is used
|
||||
const response = await publicGraphQLClient.query(authCheckEmailQuery, { email }).toPromise()
|
||||
return response.data.isEmailUsed
|
||||
},
|
||||
authSendLink: async ({ email }) => {
|
||||
// send link with code on email
|
||||
const response = await publicGraphQLClient.query(authSendLinkMutation, { email }).toPromise()
|
||||
return response.data.reset
|
||||
},
|
||||
authConfirmCode: async ({ code }) => {
|
||||
// confirm email with code from link
|
||||
const response = await publicGraphQLClient.query(authConfirmCodeMutation, { code }).toPromise()
|
||||
return response.data.reset
|
||||
},
|
||||
|
||||
getTopArticles: async () => {
|
||||
const response = await publicGraphQLClient.query(articlesTopRated, { limit: 10, offset: 0 }).toPromise()
|
||||
return response.data.topOverall
|
||||
|
@ -150,40 +179,6 @@ export const apiClient = {
|
|||
return response.data.unfollow
|
||||
},
|
||||
|
||||
// auth
|
||||
|
||||
signIn: async ({ email, password }) => {
|
||||
const response = await publicGraphQLClient.query(authLogin, { email, password }).toPromise()
|
||||
return response.data.signIn
|
||||
},
|
||||
signUp: async ({ email, password }) => {
|
||||
const response = await publicGraphQLClient.query(authRegister, { email, password }).toPromise()
|
||||
return response.data.registerUser
|
||||
},
|
||||
signOut: async () => {
|
||||
const response = await publicGraphQLClient.query(authLogout, {}).toPromise()
|
||||
return response.data.signOut
|
||||
},
|
||||
signCheck: async ({ email }) => {
|
||||
// check if email is used
|
||||
const response = await publicGraphQLClient.query(authCheck, { email }).toPromise()
|
||||
return response.data.isEmailUsed
|
||||
},
|
||||
signReset: async ({ email }) => {
|
||||
// send reset link with code on email
|
||||
const response = await publicGraphQLClient.query(authForget, { email }).toPromise()
|
||||
return response.data.reset
|
||||
},
|
||||
signResend: async ({ email }) => {
|
||||
// same as reset if code is expired
|
||||
const response = await publicGraphQLClient.query(authResend, { email }).toPromise()
|
||||
return response.data.resend
|
||||
},
|
||||
signResetConfirm: async ({ code }) => {
|
||||
// confirm reset password with code
|
||||
const response = await publicGraphQLClient.query(authReset, { code }).toPromise()
|
||||
return response.data.reset
|
||||
},
|
||||
getSession: async () => {
|
||||
// renew session with auth token in header (!)
|
||||
const response = await privateGraphQLClient.mutation(mySession, {}).toPromise()
|
||||
|
@ -247,7 +242,7 @@ export const apiClient = {
|
|||
})
|
||||
.toPromise()
|
||||
|
||||
return response.data.reactionsByShout
|
||||
return response.data?.reactionsByShout
|
||||
},
|
||||
getAuthorsBySlugs: async ({ slugs }) => {
|
||||
const response = await publicGraphQLClient.query(authorsBySlugs, { slugs }).toPromise()
|
||||
|
|
|
@ -30,12 +30,12 @@ async function handle(req, res) {
|
|||
}
|
||||
|
||||
const server = createServer((req, res) => {
|
||||
handle(req, res).catch((err) => {
|
||||
console.error('[ssr] server error', err);
|
||||
handle(req, res).catch((error) => {
|
||||
console.error('[ssr] server error', error);
|
||||
res.writeHead(500, {
|
||||
'Content-Type': 'text/plain',
|
||||
});
|
||||
res.end(err.toString());
|
||||
res.end(error.toString());
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -43,4 +43,4 @@ server.listen(8085);
|
|||
console.log('[ssr] serving at http://localhost:8085');
|
||||
|
||||
// Silence weird <time> warning
|
||||
console.error = () => {};
|
||||
console.error = () => {};
|
||||
|
|
Loading…
Reference in New Issue
Block a user