-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
569 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
NEXT_PUBLIC_SUPERTOKENS_APP_NAME=test | ||
NEXT_PUBLIC_SUPERTOKENS_API_DOMAIN=http://localhost:3000 | ||
NEXT_PUBLIC_SUPERTOKENS_WEBSITE_DOMAIN=http://localhost:3000 | ||
NEXT_PUBLIC_SUPERTOKENS_API_BASE_PATH=/api/auth | ||
NEXT_PUBLIC_SUPERTOKENS_WEBSITE_BASE_PATH=/auth |
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,98 @@ | ||
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. | ||
* | ||
* This software is licensed under the Apache License, Version 2.0 (the | ||
* "License") as published by the Apache Software Foundation. | ||
* | ||
* You may not use this file except in compliance with the License. You may | ||
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/* | ||
* Imports. | ||
*/ | ||
import { SuperTokensWrapper } from "./components/supertokensWrapper"; | ||
import SuperTokens from "./superTokens"; | ||
import { useTranslation } from "./translation/translationContext"; | ||
import { useUserContext } from "./usercontext"; | ||
import { getNormalisedUserContext } from "./utils"; | ||
|
||
import type { TranslationStore } from "./translation/translationHelpers"; | ||
import type { Navigate, SuperTokensConfig, UserContext } from "./types"; | ||
|
||
/* | ||
* API Wrapper exposed to user. | ||
*/ | ||
|
||
export default class SuperTokensNextjsAPIWrapper { | ||
static SuperTokensWrapper = SuperTokensWrapper; | ||
static router: { push: (url: string) => void }; | ||
static pathName: string; | ||
static config: SuperTokensConfig; | ||
|
||
static init(config: SuperTokensConfig) { | ||
SuperTokensNextjsAPIWrapper.config = config; | ||
// eslint-disable-next-line | ||
if (typeof window !== "undefined") { | ||
console.log("initializing"); | ||
SuperTokens.init({ | ||
...config, | ||
windowHandler: (original) => ({ | ||
...original, | ||
location: { | ||
...original.location, | ||
getPathName: () => SuperTokensNextjsAPIWrapper.pathName, | ||
assign: (url) => SuperTokensNextjsAPIWrapper.router.push(url.toString()), | ||
setHref: (url) => SuperTokensNextjsAPIWrapper.router.push(url.toString()), | ||
}, | ||
}), | ||
}); | ||
} | ||
} | ||
|
||
static setRouterData(router: { push: (url: string) => void }, pathName: string) { | ||
SuperTokensNextjsAPIWrapper.router = router; | ||
SuperTokensNextjsAPIWrapper.pathName = pathName; | ||
} | ||
|
||
static changeLanguage(language: string): Promise<void> { | ||
return SuperTokens.getInstanceOrThrow().changeLanguage(language); | ||
} | ||
|
||
static loadTranslation(store: TranslationStore): void { | ||
return SuperTokens.getInstanceOrThrow().loadTranslation(store); | ||
} | ||
|
||
static redirectToAuth = async (options?: { | ||
show?: "signin" | "signup"; | ||
navigate?: Navigate; | ||
queryParams?: any; | ||
redirectBack?: boolean; | ||
userContext?: UserContext; | ||
}) => { | ||
return SuperTokens.getInstanceOrThrow().redirectToAuth({ | ||
...options, | ||
redirectBack: options?.redirectBack ?? true, | ||
userContext: getNormalisedUserContext(options?.userContext), | ||
}); | ||
}; | ||
|
||
static useTranslation = useTranslation; | ||
|
||
static useUserContext = useUserContext; | ||
} | ||
|
||
export const init = SuperTokensNextjsAPIWrapper.init; | ||
export const changeLanguage = SuperTokensNextjsAPIWrapper.changeLanguage; | ||
export const loadTranslation = SuperTokensNextjsAPIWrapper.loadTranslation; | ||
export const redirectToAuth = SuperTokensNextjsAPIWrapper.redirectToAuth; | ||
export const setRouterData = SuperTokensNextjsAPIWrapper.setRouterData; | ||
|
||
export { SuperTokensWrapper } from "./components/supertokensWrapper"; | ||
export { useTranslation } from "./translation/translationContext"; | ||
export { useUserContext } from "./usercontext"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
|
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,99 @@ | ||
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. | ||
* | ||
* This software is licensed under the Apache License, Version 2.0 (the | ||
* "License") as published by the Apache Software Foundation. | ||
* | ||
* You may not use this file except in compliance with the License. You may | ||
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/* | ||
* Imports. | ||
*/ | ||
import { SuperTokensWrapper } from "../components/supertokensWrapper"; | ||
import SuperTokens from "../superTokens"; | ||
import { useTranslation } from "../translation/translationContext"; | ||
import { useUserContext } from "../usercontext"; | ||
import { getNormalisedUserContext } from "../utils"; | ||
|
||
import { getAppInfoFromEnv } from "./utils"; | ||
|
||
// import { SSRConfig } from "./ssr"; | ||
|
||
import type { TranslationStore } from "../translation/translationHelpers"; | ||
import type { Navigate, SuperTokensConfig, UserContext } from "../types"; | ||
|
||
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||
|
||
export default class SuperTokensNextjsAPIWrapper { | ||
static SuperTokensWrapper = SuperTokensWrapper; | ||
static router: { push: (url: string) => void }; | ||
static pathName: string; | ||
|
||
static init(config: Optional<SuperTokensConfig, "appInfo">) { | ||
const appInfo = config.appInfo || getAppInfoFromEnv(); | ||
// eslint-disable-next-line | ||
if (typeof window !== "undefined") { | ||
SuperTokens.init({ | ||
...config, | ||
appInfo, | ||
windowHandler: (original) => ({ | ||
...original, | ||
location: { | ||
...original.location, | ||
getPathName: () => SuperTokensNextjsAPIWrapper.pathName, | ||
assign: (url) => SuperTokensNextjsAPIWrapper.router.push(url.toString()), | ||
setHref: (url) => SuperTokensNextjsAPIWrapper.router.push(url.toString()), | ||
}, | ||
}), | ||
}); | ||
} | ||
} | ||
|
||
static setRouterData(router: { push: (url: string) => void }, pathName: string) { | ||
SuperTokensNextjsAPIWrapper.router = router; | ||
SuperTokensNextjsAPIWrapper.pathName = pathName; | ||
} | ||
|
||
static changeLanguage(language: string): Promise<void> { | ||
return SuperTokens.getInstanceOrThrow().changeLanguage(language); | ||
} | ||
|
||
static loadTranslation(store: TranslationStore): void { | ||
return SuperTokens.getInstanceOrThrow().loadTranslation(store); | ||
} | ||
|
||
static redirectToAuth = async (options?: { | ||
show?: "signin" | "signup"; | ||
navigate?: Navigate; | ||
queryParams?: any; | ||
redirectBack?: boolean; | ||
userContext?: UserContext; | ||
}) => { | ||
return SuperTokens.getInstanceOrThrow().redirectToAuth({ | ||
...options, | ||
redirectBack: options?.redirectBack ?? true, | ||
userContext: getNormalisedUserContext(options?.userContext), | ||
}); | ||
}; | ||
|
||
static useTranslation = useTranslation; | ||
|
||
static useUserContext = useUserContext; | ||
} | ||
|
||
export const init = SuperTokensNextjsAPIWrapper.init; | ||
export const changeLanguage = SuperTokensNextjsAPIWrapper.changeLanguage; | ||
export const loadTranslation = SuperTokensNextjsAPIWrapper.loadTranslation; | ||
export const redirectToAuth = SuperTokensNextjsAPIWrapper.redirectToAuth; | ||
export const setRouterData = SuperTokensNextjsAPIWrapper.setRouterData; | ||
|
||
export { SuperTokensWrapper } from "../components/supertokensWrapper"; | ||
export { useTranslation } from "../translation/translationContext"; | ||
export { useUserContext } from "../usercontext"; |
Oops, something went wrong.